ComboBox color changed when changed from Dropdown to DropdownList

VAer 756 Reputation points
2021-01-07T02:59:33.003+00:00

Before: It is Dropdown, inside comboBox, it is white color background.

Now: It is Dropdown List, the color inside comboBox turns to grey.

How to change it back to white? I did not find it in property.

Thanks.

Windows Forms
Windows Forms
A set of .NET Framework managed libraries for developing graphical user interfaces.
1,837 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Daniel Zhang-MSFT 9,616 Reputation points
    2021-01-07T06:05:29.52+00:00

    Hi VAer-4038,
    You can set FlatStyle property to Popup or Flat in ComboxBox's properties page, and the back color will use in both DropDown and DropDownList mode.
    54292-17.png
    More discussions about this problem, you can refer to these threads.
    How to change the BackColor of a ComboBox when DropdownStyle is DropDownList?
    Combobox DropDownList Style with white background
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


  2. Daniel Zhang-MSFT 9,616 Reputation points
    2021-01-08T08:29:43.143+00:00

    Hi VAer-4038,
    In ComboBox Properties page, change DrawMode to OwnerDrawFixed which makes you don't see any items in ComboBox.
    So you need to draw something on the given Graphics object in the ComboBox1_DrawItem event.
    Test code:

    private void Form1_Load(object sender, EventArgs e)  
    {  
        comboBox1.Items.Add("a");  
        comboBox1.Items.Add("b");  
        comboBox1.Items.Add("c");  
    }  
    private void comboBox1_DrawItem(object sender, DrawItemEventArgs e)  
    {  
        var Brush = Brushes.Black;  
      
        var Point = new Point(2, e.Index * e.Bounds.Height + 1);  
        int index = e.Index >= 0 ? e.Index : 0;  
        e.Graphics.FillRectangle(new SolidBrush(comboBox1.BackColor), new Rectangle(Point, e.Bounds.Size));  
        e.Graphics.DrawString(comboBox1.Items[index].ToString(), e.Font, Brush, e.Bounds, StringFormat.GenericDefault);  
    }  
    

    Test result:
    54736-18.gif
    Best Regards,
    Daniel Zhang


    If the response is helpful, please click "Accept Answer" and upvote it.

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.