• 转的: 重绘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);
    }

  • 相关阅读:
    Hitachi Programming Contest 2020 E Odd Sum Rectangle
    CF1060F Shrinking Tree
    UR #19
    AGC041F Histogram Rooks
    JOISC2020 Legendary Dango Maker
    Dinic 二分图匹配 / Hopcroft-Karp 算法 复杂度简单证明
    Codechef March Challenge 2020 Division 1 BREAK
    Tomorrow will be fine.
    JOISC2019 穿越时空 Bitaro
    POI2011 Periodicity
  • 原文地址:https://www.cnblogs.com/china-guoch/p/4866266.html
Copyright © 2020-2023  润新知