I have found the following solution: If I put in the designer:
this.comboBox1.BackColor = System.Drawing.Color.White; //or any other color
this.comboBox1.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; //it has to be that style
I'm able to change the color of comboBox1 - it won't always be grey.
It should be DropDownList and also BackColor should be placed in the designer.
Is it a bug or a feature?
Make custom combobox, and then in WndProc set BackColor for disabled control.
public class ComboBoxCustom : ComboBox {
[DllImport("gdi32.dll")]
internal static extern IntPtr CreateSolidBrush(int color);
[DllImport("gdi32.dll")]
internal static extern int SetBkColor(IntPtr hdc, int color);
protected override void WndProc(ref Message m){
base.WndProc(ref m);
IntPtr brush;
switch (m.Msg){
case (int)312:
SetBkColor(m.WParam, ColorTranslator.ToWin32(this.BackColor));
brush = CreateSolidBrush(ColorTranslator.ToWin32(this.BackColor));
m.Result = brush;
break;
default:
break;
}
}
}
The DropDownList is allowed the change of BackColor, and no need to set the colour in the Designer, just set the comboBox property to DropDownList in the properties pane.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With