首页 > 其他 > 详细

转的: 重绘ListView 修改标题颜色

时间:2015-10-10 12:10:53      阅读:277      评论:0      收藏:0      [点我收藏+]

 

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);
}

转的: 重绘ListView 修改标题颜色

原文:http://www.cnblogs.com/china-guoch/p/4866266.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!