日期:2014-05-18 浏览次数:21176 次
public Form9()
{
InitializeComponent();
}
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
string s = this.listBox1.Items[e.Index].ToString();
Brush b;
switch (s)
{
case "成功":
b = new SolidBrush(Color.Blue);
break;
case "失败":
b = new SolidBrush(Color.Red);
break;
default:
b = new SolidBrush(this.ForeColor);
break;
}
e.Graphics.DrawString(s, this.Font, b, e.Bounds);
}
private void Form9_Activated(object sender, EventArgs e)
{
listBox1.Items.Clear();
listBox1.Items.AddRange(new Object[] { "成功", "失败", "其他" });
}
private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
{
this.textBox1.Text = this.listBox1.SelectedItem.ToString();
}
------解决方案--------------------
可以选定,只是没有画出来吧
e.DrawBackground()就是把选定的哪个蓝条画出来,你也可以不使用它,自己画其它颜色
------解决方案--------------------