Today, I made a little thing. I need to customize the combobox drop-down box, as shown in when the drop-down box is opened.
Select one, as shown in figure.
The implementation method is to set the DrawoMode of combobox to OwnerDrawVariable and then process the DrawItem Event. For details, see the code of ComboBox. DrawItem Event (System. Windows. Forms) as follows:
1 private void cb_Risk_DrawItem (object sender, DrawItemEventArgs e)
2 {
3 if (e. Index <0) return;
4
5 switch (e. Index)
6 {
7 case 0:
8 e. Graphics. FillRectangle (Brushes. Red, e. Bounds );
9 break;
10 case 1:
11 e. Graphics. FillRectangle (Brushes. Yellow, e. Bounds );
12 break;
13 case 2:
14 e. Graphics. FillRectangle (Brushes. Blue, e. Bounds );
15 break;
16 default:
17 break;
18}
19 e. Graphics. DrawString (cb_Risk.Items [e. Index]. ToString (), cb_Risk.Font, Brushes. Black, (RectangleF) e. Bounds );
20}
By the way, my code here is stuck with The addin of CopySourceAsHtml VS. For VS2010, this article CopyAsHtml in Visual Studio 2010-AppliSec has a workaround.