winform checkedlistbox 设置行颜色
2021-03-28 20:27
标签:pre base rgs ack rap nta 定义 sha 对象 重写OnDrawItem事件 自定义时,需要重新声明DrawItemEventArgs对象,然后调用base.OndrawItem方法。 如果想根据Item内容绘制不同样式的Item时,只需要在该事件中访问e.Index即可。 winform checkedlistbox 设置行颜色 标签:pre base rgs ack rap nta 定义 sha 对象 原文地址:https://www.cnblogs.com/lucika/p/9316119.htmlpublic class ColorCodedCheckedListBox : CheckedListBox{
protected override void OnDrawItem(DrawItemEventArgs e)
{
base.OnDrawItem(e);
}
}
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);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);
}
文章标题:winform checkedlistbox 设置行颜色
文章链接:http://soscw.com/index.php/essay/69210.html