加载中…
个人资料
  • 博客等级:
  • 博客积分:
  • 博客访问:
  • 关注人气:
  • 获赠金笔:0支
  • 赠出金笔:0支
  • 荣誉徽章:
正文 字体大小:

C#中改变ListView中ColumnHeader的颜色

(2011-01-25 15:05:24)
标签:

it

    下面图是我改变后的效果,红色的是ListView的ColumnHeader:

    http://s15/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);
        }
    }

0

阅读 收藏 喜欢 打印举报/Report
  

新浪BLOG意见反馈留言板 欢迎批评指正

新浪简介 | About Sina | 广告服务 | 联系我们 | 招聘信息 | 网站律师 | SINA English | 产品答疑

新浪公司 版权所有