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

  • 相关阅读:
    友链
    P2572 [SCOI2010]序列操作
    「THP3考前信心赛」解题报告
    DP中的树上边/点覆盖问题
    P3413 SAC#1
    luoguP6754 [BalticOI 2013 Day1] Palindrome-Free Numbers
    睿智错误
    常见套路?
    奇怪的点子
    最近做过一些比较好的题
  • 原文地址:https://www.cnblogs.com/chuncn/p/1553844.html
Copyright © 2011-2022 走看看