By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
434,587 Members | 1,070 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 434,587 IT Pros & Developers. It's quick & easy.

Custom Combo Box re-draw problem

P: n/a
I’m having problems with a custom Combo box. The main problem is that I want
to modify the look of the combo which includes the size of the button. To do
this I have inherited from the standard combo set it as a UserPaint and
provided my own paint. This along with the standard Owner Draw for the list
items works fine for the DropDownList version, the problems start with the
versions with the edit box which are where the problems are.

So to get hold of the edit box so I can modify it I have subclassed it using
a NativeWindow class via a DllImported ComboBoxInfo method to get the edit
box Windows handle. After this I can resize the Edit box to fit (as I
resized the button) and to set the font to that of the main Combo box using
other DllImport methods (SendMessage, SetWindowPos etc). The problem is in
the edit box’s painting of its background… it doesn’t. If you delete text
the cursor moved but the text stays there and if you coved the combo box with
another Window and then switch back, the background if not repainted and the
covering Window graphics remain.

Anyone got any ideas? I do have a sample solution is anyone is interested.

Jan 31 '06 #1
Share this Question
Share on Google+
9 Replies


P: n/a
Hello Duncan,

If it is convenient for you, could you please upload a simple sample to
demo it? Please list the detailed repro steps and we will help look into it
for you.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://msdn.microsoft.com/subscripti...gednewsgroups/

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 1 '06 #2

P: n/a
Hi

Yes, is there another location to upload files to? Sorry if that's a daft
question, but I'm a newbie here.

Thanks

Duncan

"Yan-Hong Huang[MSFT]" wrote:
Hello Duncan,

If it is convenient for you, could you please upload a simple sample to
demo it? Please list the detailed repro steps and we will help look into it
for you.

Thanks very much.

Best regards,
Yanhong Huang
Microsoft Community Support

Get Secure! ¨C www.microsoft.com/security
Register to Access MSDN Managed Newsgroups!
http://msdn.microsoft.com/subscripti...gednewsgroups/

This posting is provided "AS IS" with no warranties, and confers no rights.

Feb 1 '06 #3

P: n/a
Hi Duncan,

Thanks for your feedback.

You can use Outlook Express to attach the sample demo project in a
reply(Use the "Insert" menu in Outlook Express reply window).

However, before this, I have some questions regarding your issue.

Based on my understanding, you are doing owner-draw with combobox in .Net.
Can you show me what does the this sentense mean: "modify the look of the
combo which includes the size of the button"? Is the "button" the dropdown
arrow of combobox?

I am not sure why you have to use NativeWindow class to do subclassing. To
do owner-draw with combobx, we only need to handle MeasuareItem and
DrawItem events. For a sample, please refer to the article below:
"Owner Draw ComboBox"
http://www.csharphelp.com/archives2/archive316.html
"Create Owner-Draw List and Combo Boxes with .NET (cont'd)"
http://www.devx.com/dotnet/Article/8014/0/page/3

If you want to draw on Edit portion of combobox, please refer to the
article below:
"Adding an Icon or Control to a TextBox or ComboBox"
http://www.vbaccelerator.com/home/NE...d_ComboBox/Tex
tBox_Icon/article.asp

Hope this 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.

Feb 2 '06 #4

P: n/a
Hi Jeffrey

An answer from my colleague who is actually working on the control, wth
regard to the 2 articles you referred to:

Actually I want to do both. Redrawing in the listbox works fine. Using a
technique similar to the vbacceleratro article (they use NativeWindow) I am
getting the textbox in order to adjust the size and font but in my case the
textbox does not repaint it's background properly.
He is putting together a simple demo.

Unfortunately we are not able to use Outlook Express (or any other news
reader) as NNTP is blocked on our network so I have to use the web-based
reader. I can't see any way to upload a demo using that. Is there someone I
can email it to?

Duncan
""Jeffrey Tan[MSFT]"" wrote:
Hi Duncan,

Thanks for your feedback.

You can use Outlook Express to attach the sample demo project in a
reply(Use the "Insert" menu in Outlook Express reply window).

However, before this, I have some questions regarding your issue.

Based on my understanding, you are doing owner-draw with combobox in .Net.
Can you show me what does the this sentense mean: "modify the look of the
combo which includes the size of the button"? Is the "button" the dropdown
arrow of combobox?

I am not sure why you have to use NativeWindow class to do subclassing. To
do owner-draw with combobx, we only need to handle MeasuareItem and
DrawItem events. For a sample, please refer to the article below:
"Owner Draw ComboBox"
http://www.csharphelp.com/archives2/archive316.html
"Create Owner-Draw List and Combo Boxes with .NET (cont'd)"
http://www.devx.com/dotnet/Article/8014/0/page/3

If you want to draw on Edit portion of combobox, please refer to the
article below:
"Adding an Icon or Control to a TextBox or ComboBox"
http://www.vbaccelerator.com/home/NE...d_ComboBox/Tex
tBox_Icon/article.asp

Hope this 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.

Feb 2 '06 #5

P: n/a
Hi Duncan,

Thanks for your feedback.

If you can create a simple sample project, you can send it to me at:
je***@online.microsoft.com(remove "online."). I will give a review. Thanks

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.

Feb 3 '06 #6

P: n/a
Hi Jeffrey

Hopefully you have received the example code from my colleague, Simon Smith.

Regards

Duncan
""Jeffrey Tan[MSFT]"" wrote:
Hi Duncan,

Thanks for your feedback.

If you can create a simple sample project, you can send it to me at:
je***@online.microsoft.com(remove "online."). I will give a review. Thanks

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.

Feb 7 '06 #7

P: n/a
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.
Feb 8 '06 #8

P: n/a
Thanks for that.

I have just tried your idea in my project and that sorts out the problem
nicely.

""Jeffrey Tan[MSFT]"" wrote:
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.

Feb 9 '06 #9

P: n/a
I am glad it can help you. If you need further help, please feel free to
post. Thanks

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.

Feb 10 '06 #10

This discussion thread is closed

Replies have been disabled for this discussion.