Customize the C # combobox drop-down box

Source: Internet
Author: User

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;


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;


19 e. Graphics. DrawString (cb_Risk.Items [e. Index]. ToString (), cb_Risk.Font, Brushes. Black, (RectangleF) e. Bounds );


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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.