日期:2014-05-18  浏览次数:21125 次

listbox选择条的颜色怎么可以变成其他颜色,比如变成灰色
listbox选择条的颜色怎么可以变成其他颜色,比如变成灰色

------解决方案--------------------
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
listBox1.DrawMode = DrawMode.OwnerDrawFixed;
e.DrawBackground();
Brush myBrush = Brushes.Black;

switch (e.Index)
{
case 0: myBrush = Brushes.Red; break;

case 1: myBrush = Brushes.Orange; break;

case 2: myBrush = Brushes.Purple; break;
}

e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font,myBrush,e.Bounds,StringFormat.GenericDefault);
e.DrawFocusRectangle();
}
参考....
------解决方案--------------------
探讨
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
listBox1.DrawMode = DrawMode.OwnerDrawFixed;
e.DrawBackground();
Brush myBrush = Brushes.Black;

switch (e.Index)
{
case 0: myBrush = Brushes.Red; break;

case 1: myBrush = Brushes.Orange; break;

case 2: myBrush = Brushes.Purple; break;
}

e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font,myBrush,…