一、说明
ListBox自身的OnDrawItem函数是专门绘制item样式的,只需要重载即可
protected override void OnDrawItem(DrawItemEventArgs e)
{
e.DrawBackground();
e.DrawFocusRectangle();
// 确保listbox中有日志且该日志被记录在字典中
if (e.Index >= 0 && m_dicItems.Keys.Contains(e.Index))
{
e.Graphics.DrawString(m_dicItems[e.Index].info, Font, new SolidBrush(m_dicItems[e.Index].color), e.Bounds);
}
}
注意,listBox一定要设置成
this.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawVariable;
二、那么就开始实现,添加一个组件继承自ListBox
1.先定义一个结构,用于保存item的index、info和color
class LogItem
{
public String info;
public int index;
public



被折叠的 条评论
为什么被折叠?



