1: /// <summary>
2: /// 根据不同Type变量,ListBox的选项显示不同的颜色
3: /// </summary>
4: /// <param name="Type">类型ID号</param>
5: /// <param name="lv">ListBox</param>
6: /// <param name="e"></param>
7: public static void ListBoxDrawItem(int Type, ListBox lv, DrawItemEventArgs e)
8: {
9: lv.DrawMode = DrawMode.OwnerDrawFixed;
10: e.DrawBackground();
11: Brush myBrush = Brushes.Black;
12: switch (Type)
13: {
14: case 1: myBrush = Brushes.Red; break;
15: case 2: myBrush = Brushes.Blue; break;
16: case 3: myBrush = Brushes.Black; break;
17: }
18: e.Graphics.DrawString(lv.Items[e.Index].ToString(), e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
19: e.DrawFocusRectangle();
20: }