zoukankan      html  css  js  c++  java
  • winform checkedlistbox 设置行颜色

    重写OnDrawItem事件

    public class ColorCodedCheckedListBox : CheckedListBox{
        protected override void OnDrawItem(DrawItemEventArgs e)
        {
             base.OnDrawItem(e);
        }
    }    
    

      自定义时,需要重新声明DrawItemEventArgs对象,然后调用base.OndrawItem方法。

    DrawItemEventArgs e2 = new DrawItemEventArgs(e.Graphics, e.Font, new Rectangle(e.Bounds.Location, e.Bounds.Size), 
    e.Index, (e.State & DrawItemState.Focus) == DrawItemState.Focus ? DrawItemState.Focus : DrawItemState.None, Color.Orange, this.BackColor);

    如果想根据Item内容绘制不同样式的Item时,只需要在该事件中访问e.Index即可。

    protected override void OnDrawItem(DrawItemEventArgs e)
            {
                if(e.Index%2==0)
                {
                    DrawItemEventArgs e2 = new DrawItemEventArgs(e.Graphics, e.Font, 
    new Rectangle(e.Bounds.Location, e.Bounds.Size),
    e.Index, (e.State & DrawItemState.Focus) == DrawItemState.Focus ? DrawItemState.Focus : DrawItemState.None, Color.Orange, this.BackColor); base.OnDrawItem(e2); } else base.OnDrawItem(e); }
  • 相关阅读:
    斜率dp cdq 分治
    POJ2449 (k短路)
    BZOJ1576 (最短路+并查集)
    SWUST0249 (凸包面积)
    道路修建 (网络流)
    HDU3930 (原根)
    ZOJ2006 (后缀自动机)
    Codechef2015 May
    后缀自动机
    Digit (数位DP)
  • 原文地址:https://www.cnblogs.com/lucika/p/9316119.html
Copyright © 2011-2022 走看看