如何在System.Windows.Forms.ListBox中設置特定項目的背景顏色?我希望能夠設置多個。
3 回答

月關寶盒
TA貢獻1772條經(jīng)驗 獲得超5個贊
可能做到這一點的唯一方法是自己繪制項目。
設置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,盡管它們還有另一種實現(xiàn)方式(不是真正的數(shù)據(jù)綁定,但是在列方式上更靈活)
- 3 回答
- 0 關注
- 1063 瀏覽
添加回答
舉報
0/150
提交
取消