|
private void listBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
listBox1.DrawMode = DrawMode.OwnerDrawFixed;
e.DrawBackground();
Brush myBrush = Brushes.Black;
switch (e.Index)
{
case 0: myBrush = Brushes.Red; break;
case 1: myBrush = Brushes.Orange; break;
case 2: myBrush = Brushes.Purple; break;
}
e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, myBrush,
e.Bounds,StringFormat.GenericDefault);
e.DrawFocusRectangle();
}
private void button1_Click(object sender, EventArgs e)
{
listBox1.Items.Add("Blue!");
listBox1.Items.Add("What colour?");
}
Form里面就是一个button和一个listbox,可是最后listbox里面显示的是没有颜色,但是有东西输入,因为多次点击button后会出现滑动条,怎么回事?
|
|