0

To make a list of Drop Down from designer as shown in picture I select DropDownStyle as DropDown list doing this it become a list but its background color is changed I also change BackColor property to window but color is remain same as of list now I want to Change background color of Dropdown as it is before making list.

enter image description here

csharpbd
  • 3,786
  • 4
  • 23
  • 32
M Tahir Latif
  • 11
  • 1
  • 2
  • 8
  • 1
    Possible duplicate of [How to change the BackColor of a ComboBox when DropdownStyle is DropDownList?](http://stackoverflow.com/questions/36345082/how-to-change-the-backcolor-of-a-combobox-when-dropdownstyle-is-dropdownlist) – Jimwel Anobong Apr 10 '17 at 08:14

2 Answers2

1

Change the FlatStyle property to "Flat" or "Popup". There, you can change the combobox's backcolor. However, the combobox must lose focus in order for you to see the color because when it's selected, it is blue (vary by Windows current theme) when focused indicated that you've selected the item that you've selected


Consider this image

Jimwel Anobong
  • 468
  • 5
  • 18
0

You can do this by changing DrawMode properties. After changing the DrawMode properties to DrawMode.OwnerDrawFixed, add DrawItem event and change your BackColor in within this.

Code:

private void Form1_Load(object sender, EventArgs e)
{
    comboBox1.DrawMode = DrawMode.OwnerDrawFixed;
    comboBox1.DrawItem += new DrawItemEventHandler(comboBox1_DrawItem);
}

private void comboBox1_DrawItem(object sender, System.Windows.Forms.DrawItemEventArgs e)
{
    try
    {
        // Draw the background of the ListBox control for each item.
        e.DrawBackground();
        // Define the default color of the brush as black.
        Brush myBrush = Brushes.Black;

        // Draw the current item text based on the current Font 
        // and the custom brush settings.
        e.Graphics.DrawString(comboBox1.Items[e.Index].ToString(), e.Font, myBrush, e.Bounds, StringFormat.GenericDefault);
        // If the ListBox has focus, draw a focus rectangle around the selected item.
        e.DrawFocusRectangle();
    }
    catch (Exception ex)
    {

    }
}

Output:

enter image description here

See System.Windows.Forms.DrawMode for more information.

csharpbd
  • 3,786
  • 4
  • 23
  • 32