Click here to Skip to main content
15,877,754 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I try change font color of disabled combobox and cant find any solution. Mabe someone know how to do this? Propably I must ovveride WndProc... but witch message?
Posted
Comments
/\jmot 27-Nov-14 13:10pm    
post your code here, what you tried so far??

So far i made own combobox that have white back color when is disabled (using internet obviously:)). Now I need add code, that change font color from gray to black.

C#
public partial class OwnComboBox : 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;
        }
    }

}
 
Share this answer
 
I have searched around for information in the past about this, and as far as I can tell, the best solution is to change the DrawMode of the combo box to OwnerDrawFixed or OwnerDrawVariable and then write your own drawing code in the DrawItem event of the combo box.

I found this article that goes into much more detail about it. Hope it helps.
 
Share this answer
 
Comments
magnum100 28-Nov-14 12:10pm    
I try with DrawItem event, but only what I achieved was changing color of items when combobox is dropdown. But when is disabled looks like usual (gray).
Maby You have some code to test?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900