Thanks for that.
I have just tried your idea in my project and that sorts out the problem
nicely.
""Jeffrey Tan[MSFT]"" wrote:
[color=blue]
> Hi Duncan,
>
> Thanks for your feedback.
>
> Yes, I have received the sample project and given it a review. It seems
> that your current problem is how to set the edit portion of combobox
> background color. Actually, Edit control will send a WM_CTLCOLOREDIT
> notification message to its parent window(combobox in our scenario) when
> the control is about to be drawn. By responding to this message, the parent
> window can use the specified device context handle to set the text and
> background colors of the edit control.
>
> Below is the code snippet I added to the MyCombo class, after adding this
> code snippet, it works well on my side now:
>
> int WM_CTLCOLOREDIT = 0x133;
> IntPtr hBrush = IntPtr.Zero;
>
> [DllImport("gdi32.dll", EntryPoint = "CreateSolidBrush", CharSet =
> CharSet.Auto, SetLastError = true, ExactSpelling = true)]
> private static extern IntPtr CreateSolidBrush(int crColor);
> [DllImport("gdi32.dll", CharSet = CharSet.Auto, SetLastError = true,
> ExactSpelling = true)]
> public static extern int SetBkColor(IntPtr hDC, int clr);
>
> protected override void WndProc(ref Message m)
> {
> if (m.Msg == WM_CTLCOLOREDIT)
> {
> IntPtr hdcEdit = m.WParam;
> IntPtr hEdit = m.LParam;
> if (hEdit != IntPtr.Zero && hdcEdit != IntPtr.Zero)
> {
> hBrush= CreateSolidBrush(ColorToCOLORREF(Color.Blue));
> SetBkColor(hdcEdit, ColorToCOLORREF(Color.Blue));
> m.Result = hBrush;
> return;
> }
> }
> base.WndProc(ref m);
> }
>
> public static int ColorToCOLORREF(Color color)
> {
> return ((color.R | (color.G << 8)) | (color.B << 0x10));
> }
>
> Hope it helps
>
> Best regards,
> Jeffrey Tan
> Microsoft Online Partner Support
> Get Secure! -
www.microsoft.com/security
> This posting is provided "as is" with no warranties and confers no rights.
>
>
>[/color]