ListBox项的背景色(winforms)

如何在System.Windows.Forms.ListBox中设置特定项目的背景颜色?我希望能够设置多个。



翻阅古今
浏览 1037回答 3
3回答

月关宝盒

可能做到这一点的唯一方法是自己绘制项目。设置DrawMode为OwnerDrawFixed并在DrawItem事件上编写如下代码: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,尽管它们还有另一种实现方式(不是真正的数据绑定,但是在列方式上更灵活)
打开App,查看更多内容
随时随地看视频慕课网APP