zoukankan      html  css  js  c++  java
  • 转的: 重绘ListView 修改标题颜色

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

  • 相关阅读:
    全栈工程师学习Linux技术的忠告
    实战CentOS系统部署Hadoop集群服务
    如何安装最新的 XFCE 桌面?
    scrapy爬虫框架(二)
    scrapy爬虫框架(一)
    数据结构与算法(二)
    IDEA 常用快捷键
    数据结构与算法(一)
    es6之模板字符串
    es6之箭头函数
  • 原文地址:https://www.cnblogs.com/china-guoch/p/4866266.html
Copyright © 2011-2022 走看看