using System;
using System.Windows.Forms;
using System.Drawing;
public class listboxcolorrows
{
private ListBox mLB1 = new ListBox();
private void InitializeComponent()
{
//... etc.
this.mLB1.DrawItem += new DrawItemEventHandler(this.mLB1_DrawItem);
}
private void mLB1_DrawItem(object sender, DrawItemEventArgs e)
{
String s = (string) mLB1.Items[e.Index];
e.DrawBackground();
SolidBrush brush;
if (s.Equals("red"))
brush = new SolidBrush(Color.Red);
else if (s.Equals("yellow"))
brush = new SolidBrush(Color.Goldenrod);
else
brush = new SolidBrush(e.ForeColor);
e.Graphics.DrawString(s, e.Font, brush, e.Bounds);
}
}
|