private void Form1_Load(object sender, EventArgs e)
{
this.listBox1.DrawMode = DrawMode.OwnerDrawFixed;
this.listBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem);
}
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
string s = this.listBox1.Items[e.Index].ToString();
if (s.Contains("数据正常"))
{
e.Graphics.DrawString(s, this.Font, Brushes.Green, e.Bounds);
}
else if (s.Contains("数据警告"))
{
e.Graphics.DrawString(s, this.Font, Brushes.Red, e.Bounds);
}
else
e.Graphics.DrawString(s, this.Font, new SolidBrush(this.ForeColor), e.Bounds);
}
{
this.listBox1.DrawMode = DrawMode.OwnerDrawFixed;
this.listBox1.DrawItem += new System.Windows.Forms.DrawItemEventHandler(this.listBox1_DrawItem);
}
private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
{
string s = this.listBox1.Items[e.Index].ToString();
if (s.Contains("数据正常"))
{
e.Graphics.DrawString(s, this.Font, Brushes.Green, e.Bounds);
}
else if (s.Contains("数据警告"))
{
e.Graphics.DrawString(s, this.Font, Brushes.Red, e.Bounds);
}
else
e.Graphics.DrawString(s, this.Font, new SolidBrush(this.ForeColor), e.Bounds);
}