一个ListBox项的背景颜色(的WinForms) [英] Background color of a ListBox item (winforms)
本文介绍了一个ListBox项的背景颜色(的WinForms)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何设置一个特定的项目,在System.Windows.Forms.ListBox的背景颜色?我希望能够在可能的情况设置多个的。
How can I set the background color of a specific item in a System.Windows.Forms.ListBox? I would like to be able to set multiple ones if possible.
推荐答案
大概来实现这一目标的唯一方法是自己绘制的项目。
Probably the only way to accomplish that is to draw the items yourself.
将 DrawMode
到 OwnerDrawFixed
和code这样的事情在DrawItem事件:
and code something like this on the DrawItem event:
private void listBox_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
Graphics g = e.Graphics;
g.FillRectangle(new SolidBrush(Color.Silver), e.Bounds);
// Print text
e.DrawFocusRectangle();
}
第二选择是使用一个ListView,尽管它们具有实现的其他方式(结合不是真正的数据,但是在列的方式更灵活的)
Second option would be using a ListView, although they have an other way of implementations (not really data bound, but more flexible in way of columns)
这篇关于一个ListBox项的背景颜色(的WinForms)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文