本文主要是介绍C#中改变ListView中ColumnHeader的颜色,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
![C#中改变ListView中ColumnHeader的颜色 C#中改变ListView中ColumnHeader的颜色](http://s15.sinaimg.cn/middle/4b650d65g9aa65cdb9fbe&690)
步骤1:
将ListView的OwnerDraw属性改为True
步骤2:
建立ListView的DawColumnHeader消息函数
步骤3:
代码如下:
private void lsvContactRcd_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
{
int tColumnCount;
Rectangle tRect = new Rectangle();
Point tPoint=new Point();
Font tFont = new Font("宋体", 9, FontStyle.Regular);
SolidBrush tBackBrush = new SolidBrush(System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(56)))), ((int)(((byte)(56))))));
SolidBrush tFtontBrush;
tFtontBrush = new SolidBrush (System.Drawing.SystemColors.GradientActiveCaption);
if (lsvContactRcd.Columns.Count == 0)
return;
tColumnCount = lsvContactRcd.Columns.Count;
tRect.Y = 0;
tRect.Height = e.Bounds.Height - 1;
tPoint.Y = 3;
for (int i = 0; i < tColumnCount; i++)
{
if (i == 0)
{
tRect.X = 0;
tRect.Width = lsvContactRcd.Columns[i].Width;
}
else
{
tRect.X += tRect.Width;
tRect.X += 1;
tRect.Width = lsvContactRcd.Columns[i].Width - 1;
}
e.Graphics.FillRectangle(tBackBrush, tRect);
tPoint.X = tRect.X + 3;
e.Graphics.DrawString(lsvContactRcd.Columns[i].Text, tFont, tFtontBrush, tPoint);
}
}
原文地址:http://blog.sina.com.cn/s/blog_4b650d650100o6ru.html
这篇关于C#中改变ListView中ColumnHeader的颜色的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!