listview设置行高
listview本身是没有办法设置行高的,需要借助imagelist;
ImageList iList = new ImageList(); iList.ImageSize = new Size(1, 30);//宽度和高度值必须大于等于1且不超过256 listView1.SmallImageList = iList;
listview header添加边框、背景色
private void listView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { e.Graphics.FillRectangle(Brushes.LightBlue, e.Bounds); e.DrawText(); using (Pen p1 = new Pen(Color.FromArgb(227, 227, 227), 1)) { e.Graphics.DrawLine(p1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height); e.Graphics.DrawLine(p1, e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y); e.Graphics.DrawLine(p1, e.Bounds.X, e.Bounds.Y + e.Bounds.Height - 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height - 1); } }
如果用imagelist修改了行高,listView_DrawColumnHeader也要改
private void listView_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e) { Rectangle r = new Rectangle(); r.X = e.Bounds.X + 1; r.Y = e.Bounds.Y; r.Height = e.Bounds.Height; r.Width = e.Bounds.Width; e.Graphics.FillRectangle(Brushes.WhiteSmoke, r); e.DrawText(); using (Pen p1 = new Pen(Color.FromArgb(227, 227, 227), 1)) { e.Graphics.DrawLine(p1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height - 2); e.Graphics.DrawLine(p1, e.Bounds.X, e.Bounds.Y, e.Bounds.X + e.Bounds.Width, e.Bounds.Y); e.Graphics.DrawLine(p1, e.Bounds.X, e.Bounds.Y + e.Bounds.Height - 1, e.Bounds.X + e.Bounds.Width, e.Bounds.Y + e.Bounds.Height - 1); } }