473,379 Members | 2,754 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,379 software developers and data experts.

Custom Combo Box re-draw problem

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
9 6155
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
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
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
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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: SammyBar | last post by:
Hi all, I have some custom collections (ArrayList of custom Objects) and I want to display them using typical Windows form controls (DataGrid, Combo). What should I do to expose them as valid...
1
by: Robert Neville | last post by:
I am having some trouble with some old code revolving around custom form navigation buttons. My main form has a sub-form with these custom navigation buttons. In other words, the code should be...
7
by: Keith | last post by:
A2003, XP Pro SP2. I'm developing a simple custom filter form for a client and keep running into the same error. I've posted a simplified version in my web space at ...
2
by: Ron | last post by:
I need to create a custom combo box that lists items and subitems along with descriptions in a particular format. For example Format of the Data Listed In Combo Box: Item Description...
1
by: Mike Hofer | last post by:
I am trying to do something a little nonstandard, and am having some difficulty determining (a) if it can be done and (b) if so, how to do it. What I want to do is fill a dropdown combobox with...
1
by: Dan Keeley | last post by:
Hi I'm trying to create a custom combo box so i can display a nice text name but return the actual key value for the database. So i have this class ( At the bottom of this post ) How do i...
2
by: Fred Flintstone | last post by:
I'm creating a multi-column dropdown since there isn't one. My idea is to override an Infragistics Combo and add the dropdown as a grid object. So I create a basic override of the control. The...
27
by: Wayne | last post by:
I've been clicking around Access 2007 Beta 2 and can't see the custom menu bar designer. Is it in the beta? Maybe I'm blind. The question that comes to mind is: Will custom menu bars be the same...
3
by: beconrad | last post by:
Hi all, I am not sure if what I want to do is possible, and if it is I have not been able to figure out how to do it. This is what I would like: 1. I have a data entry form with a field...
2
by: =?Utf-8?B?RXJpYw==?= | last post by:
Hello All, I am currently working on an issue that has a custom control that mimics a combobox that when it has focus it continues to generate endless WM_PAINT Messages. The control in itself...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.