private void Form1_Load(object sender, EventArgs e)
{
listBox1.Items.Add("***红色");
listBox1.Items.Add("黄色");
listBox1.Items.Add("蓝色");
listBox1.DrawMode = DrawMode.OwnerDrawFixed; // 属性里设置
}
private void listbox1_DrawItem(object sender, DrawItemEventArgs e)
{
e.DrawBackground();
if (listbox1.Items[e.Index].ToString().Substring(0,1) == "*")//如果首字带*号,则红字显示
{
e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, new SolidBrush(Color.Red), e.Bounds);
}
else
{
e.Graphics.DrawString(((ListBox)sender).Items[e.Index].ToString(), e.Font, new SolidBrush(e.ForeColor), e.Bounds);
}
e.DrawFocusRectangle();
}