1、owerDraw 设置为true
2、实现事件
DrawColumnHeader
DrawItem
DrawSubItem
private void listView1_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
int tColumnCount;
Rectangle tRect = new Rectangle();
Point tPoint = new Point();
Font tFont = new Font("宋体", FontSize, FontStyle.Regular);
SolidBrush tBackBrush = new SolidBrush(System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(0)))), ((int)(((byte)(255))))));
SolidBrush tFtontBrush;
tFtontBrush = new SolidBrush(System.Drawing.SystemColors.GradientActiveCaption);
if (listView1.Columns.Count == 0)
return;
tColumnCount = listView1.Columns.Count;
tRect.Y = 0;
tRect.Height = e.Bounds.Height - 1;
tPoint.Y = sWidth;
for (int i = 0; i < tColumnCount; i++)
{
if (i == 0)
{
tRect.X = 0;
tRect.Width = listView1.Columns[i].Width;
}
else
{
tRect.X += tRect.Width;
tRect.X += 1;
tRect.Width = listView1.Columns[i].Width - 1;
}
e.Graphics.FillRectangle(tBackBrush, tRect);
tPoint.X = tRect.X + sWidth;
e.Graphics.DrawString(listView1.Columns[i].Text, tFont, tFtontBrush, tPoint);
}
}
private void listView1_DrawItem(object sender, DrawListViewItemEventArgs e)
{
Point tPoint = new Point();
SolidBrush tFrontBrush = new SolidBrush(Color.Blue);
Font tFont = new Font("宋体", FontSize, FontStyle.Regular);
tPoint.X = e.Bounds.X + 3;
tPoint.Y = e.Bounds.Y + 2;
e.Graphics.DrawString(e.Item.Text, tFont, tFrontBrush, tPoint);
}
private void listView1_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
{
Point tPoint = new Point();
SolidBrush tFrontBrush = new SolidBrush(Color.Blue);
Font tFont = new Font("宋体", FontSize, FontStyle.Regular);
tPoint.X = e.Bounds.X + 3;
tPoint.Y = e.Bounds.Y + 2;
e.Graphics.DrawString(e.SubItem.Text, tFont, tFrontBrush, tPoint);
}