日期:2014-05-18 浏览次数:21780 次
设置this.listBox1.DrawMode = System.Windows.Forms.DrawMode.OwnerDrawFixed; 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); }
private void Form1_Load(object sender, EventArgs e) { this.listBox1.DrawMode = DrawMode.OwnerDrawFixed; this.listBox1.Items.Add("aa"); this.listBox1.Items.Add("bb"); this.listBox1.Items.Add("cc"); 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("cc")) { e.Graphics.DrawString(s, this.Font, Brushes.Red, e.Bounds); } else e.Graphics.DrawString(s, this.Font, new SolidBrush(this.ForeColor), e.Bounds); }