473,651 Members | 2,716 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 6169
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.mi crosoft.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.mi crosoft.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("gdi3 2.dll", EntryPoint = "CreateSolidBru sh", CharSet =
CharSet.Auto, SetLastError = true, ExactSpelling = true)]
private static extern IntPtr CreateSolidBrus h(int crColor);
[DllImport("gdi3 2.dll", CharSet = CharSet.Auto, SetLastError = true,
ExactSpelling = true)]
public static extern int SetBkColor(IntP tr 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= CreateSolidBrus h(ColorToCOLORR EF(Color.Blue)) ;
SetBkColor(hdcE dit, ColorToCOLORREF (Color.Blue));
m.Result = hBrush;
return;
}
}
base.WndProc(re f 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("gdi3 2.dll", EntryPoint = "CreateSolidBru sh", CharSet =
CharSet.Auto, SetLastError = true, ExactSpelling = true)]
private static extern IntPtr CreateSolidBrus h(int crColor);
[DllImport("gdi3 2.dll", CharSet = CharSet.Auto, SetLastError = true,
ExactSpelling = true)]
public static extern int SetBkColor(IntP tr 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= CreateSolidBrus h(ColorToCOLORR EF(Color.Blue)) ;
SetBkColor(hdcE dit, ColorToCOLORREF (Color.Blue));
m.Result = hBrush;
return;
}
}
base.WndProc(re f 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
324
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 datasources to these controls? What if I want that these collections work with Visual Studio on design time in order to allow me easy create grid columns on design time? Can you point me to some examples? Thanks in advance
1
3547
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 modular and work across forms and sub-forms. My previous code was taken from the Access Expert Solutions 97 (Leszynski) many years ago. As my database became more complex with multiple sub-forms and intricate combo boxes, the code faltered. Some...
7
3015
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 http://keith.wilby.users.btopenworld.com/dbase/db4.zip Try this: Open frmTest, then open fdlgFilter.
2
8285
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 Item Description Subitem Description Subitem Description Subitem Description Item Description Subitem Description
1
15026
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 data from a collection. Then, I want to bind that list to a member of a custom class. (Don't ask why, just trust me on that one. <gr>). What I'm doing now is binding the combo box to a collection, as follows: Dim items As ArmorTypeCollection =...
1
1320
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 get the current value? I have customerlist which is a "comboitem2". The user has selected an item,
2
2775
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 first thing I want the control to do is kill the default button and add a new one. So in the initialization (New) area of the control I add the code to do that: Me.DropDownButtonDisplayStyle = Infragistics.Win.ButtonDisplayStyle.Never Dim...
27
45538
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 height as they were in previous versions or will they be the "ribbon" style that takes up a huge portion of the screen? Also when I use Access 2007 to open an Access 2003 database that has custom menu bars they display as they did in Access...
3
4155
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 called Insurance. That field uses a combo box which takes its information from query on the Insurance table. At the moment the drop down list is sorted in alphabetical order.
2
2698
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 is primarily a windows panel with three controls added ( textbox, combo box, and picturebox). In looking at the code for the custom control I see no issue with it. Any pointers on how to determine which likely control in this custom control...
0
8275
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8697
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
7297
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6158
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1909
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1587
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.