zoukankan      html  css  js  c++  java
  • Listview.Subitem.BackColor.ForeColor改变字体颜色和背景

    注意事项:

            一定要把listview的OwnerDraw属性设置为True(默认是False)。
           当设置OwnerDraw = True后,FullRowSelect 、HideSelection 属性好象实效了。

           添加DrawColumnHeader事件,绘制列标头用。       
           添加DrawSubItem事件,绘子项头用。


    代码如下:

            private void lvKeyPerson_DrawColumnHeader(object sender, DrawListViewColumnHeaderEventArgs e)
            {
                e.DrawBackground();
                e.DrawText();
            }
            private void lvKeyPerson_DrawSubItem(object sender, DrawListViewSubItemEventArgs e)
            {
                e.DrawBackground();
                //判断Subitem中是否存在关键字
                if (txtContent.Text.Trim().Length > 0 && e.SubItem.Text.IndexOf(txtContent.Text.Trim()) >= 0)
                {
                    e.SubItem.BackColor = Color.Pink;  //设置背景色为粉红色
                }
                else
                {
                    e.SubItem.ForeColor = Color.Black; //设置字体为红色
                }

                e.DrawText();
            }

  • 相关阅读:
    Poj(1703),种类并查集
    Poj(2236),简单并查集
    Poj (3239),m皇后问题
    Poj(1521),哈夫曼编码
    NYOJ(680),摘枇杷,(暴力,或者二分搜索)
    NYOJ(42)欧拉图
    数集合有多少个TOJ(2469)
    HDU(1016),打素数环
    HDU(4394),数论上的BFS
    Poj(2225),三维BFS
  • 原文地址:https://www.cnblogs.com/chuncn/p/1553844.html
Copyright © 2011-2022 走看看