Re: CTL_COLORSTATIC problems
From: serge gubenko (serge_gubenko_at_hotmail.com)
Date: 12/08/04
- Next message: serge gubenko: "Re: NumericUpDown Decimals"
- Previous message: Bob Powell [MVP]: "Re: How can I play movies in VB.Net"
- In reply to: Rigga: "CTL_COLORSTATIC problems"
- Messages sorted by: [ date ] [ thread ]
Date: Wed, 8 Dec 2004 12:03:11 +0200
Hi,
Looks like internal edit control of the combobox handles WM_CTLCOLORSTATIC
message results wrong when its not enabled, I guess, you could solve the
problem if this edit control will be always enabled. I tried this idea and
it seemed to work well, below is source code of my class:
_______________________________________________
public class MyComboBox : ComboBox
{
[DllImport("gdi32",CharSet=CharSet.Auto)]
internal static extern int SetTextColor(IntPtr hdc, int crColor);
[DllImport("gdi32",CharSet=CharSet.Auto)]
internal static extern int SetBkColor(IntPtr hdc, int crColor);
[DllImport("gdi32",CharSet=CharSet.Auto)]
internal static extern IntPtr CreateSolidBrush(int crColor);
[DllImport("user32", CharSet=CharSet.Auto)]
internal static extern IntPtr FindWindowEx(IntPtr hwndParent, IntPtr
hwndChildAfter,
[MarshalAs(UnmanagedType.LPTStr)] string lpszClass,
[MarshalAs(UnmanagedType.LPTStr)] string lpszWindow);
[DllImport ("user32.dll", CallingConvention = CallingConvention.StdCall,
CharSet = CharSet.Auto)]
internal static extern bool EnableWindow (IntPtr hWnd, bool bEnable);
public const int WM_CTLCOLORSTATIC = 0x0138;
public const int WM_CTLCOLOREDIT = 0x0133;
protected override void WndProc(ref Message m)
{
IntPtr xBrush;
switch (m.Msg)
{
case WM_CTLCOLORSTATIC:
IntPtr xEditHandle = FindWindowEx(this.Handle, IntPtr.Zero,
null, null);
EnableWindow(xEditHandle, true);
return;
case WM_CTLCOLOREDIT:
if (!Enabled)
{
xBrush =
CreateSolidBrush(ColorTranslator.ToWin32(Color.Black));
SetTextColor(m.WParam,
ColorTranslator.ToWin32(Color.White));
SetBkColor(m.WParam,
ColorTranslator.ToWin32(Color.Black));
}
else
{
xBrush =
CreateSolidBrush(ColorTranslator.ToWin32(BackColor));
SetTextColor(m.WParam,
ColorTranslator.ToWin32(ForeColor));
SetBkColor(m.WParam,
ColorTranslator.ToWin32(BackColor));
}
m.Result = xBrush;
return;
}
base.WndProc(ref m);
}
protected override void OnEnabledChanged(EventArgs e)
{
if (Enabled) Invalidate(true);
base.OnEnabledChanged(e);
}
}
_______________________________________________
hope this helps
Best regards, Serge Gubenko
"Rigga" <s@v.c> wrote in message
news:41b59abe$0$50865$ed2619ec@ptn-nntp-reader01.plus.net...
> Hi all,
>
> I have an overridden ComboBox that i wish to change the colour of when it
is
> disabled.
>
> I have overridden the WNDPROC and caught the CTL_COLORSTATIC message.
>
> I can now change the background colour to any colour i wish using the
> external GDI routine SetBkColor which all works fine.
>
> However the external SetTextColor routine seems to do nothing, the text
> still appears to be greyed out.
>
> Does anyone have any thoughts on what could be going wrong?
>
> Thanks in advance,
> R.
>
>
- Next message: serge gubenko: "Re: NumericUpDown Decimals"
- Previous message: Bob Powell [MVP]: "Re: How can I play movies in VB.Net"
- In reply to: Rigga: "CTL_COLORSTATIC problems"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|