473,657 Members | 2,507 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Inherit ComboBox / Windows Vista

Why when I inherit a ComboBox and make no code changes, when I set the new
control DropDownStyle to dropDownList it appears different than the standard
ComboBox control on Vista?

In Windows Vista when this mode is set, the control is all one color
indicating that you can't type in it and looks really slick. How do i
reproduce this behavior?

Apr 21 '07 #1
6 5603
Nathan Laff wrote:
Why when I inherit a ComboBox and make no code changes, when I set the
new control DropDownStyle to dropDownList it appears different than the
standard ComboBox control on Vista?

In Windows Vista when this mode is set, the control is all one color
indicating that you can't type in it and looks really slick. How do i
reproduce this behavior?
Are you overriding or modifying any behavior. Just tried it here with
my own combobox inheriting from System.Windows. Forms.ComboBox and the
display renders exactly the same as a System.Windows. Forms.ComboBox when
the DropDownStyle is set to DropDownList.
--
Tom Porterfield
Apr 21 '07 #2
Are you overriding or modifying any behavior. Just tried it here with my
own combobox inheriting from System.Windows. Forms.ComboBox and the display
renders exactly the same as a System.Windows. Forms.ComboBox when the
DropDownStyle is set to DropDownList.
Ok, here is what happened, I forgot to override OnPaint and pass in
base.OnPaint.

So that fixed the problem of a blank control not working. However I am doing
DrawMode of OwnerDrawFixed.
Basically it's drawing images next to my comboBox items. Any idea how to
maintain the look that it should, while drawing these images?

Apr 21 '07 #3
Basically it's drawing images next to mycomboBoxitems . Any idea how to
maintain the look that it should, while drawing these images?
I'm having the same issue with Vista, here's the quick code I posted
trying to get help(maybe someone in this group has some better
suggestions).

public class ColoredComboBox : ComboBox
{
public ColoredComboBox ()
{
this.DrawMode = DrawMode.OwnerD rawFixed;
this.DrawItem += new
DrawItemEventHa ndler(ColoredCo mboBox_DrawItem );
}
void ColoredComboBox _DrawItem(objec t sender, DrawItemEventAr gs e)
{
e.DrawBackgroun d();
// don't even care about text, my icon, or anything else at this
point, just want the background to work.
}
}

May 1 '07 #4
Here's what it comes down to. The Windows shell developers screwed us...

If you want to do this you have to handle WM_PAINT and paint the thing
yourself using DrawThemeBackgr ound.

Here's the long explanation of it:

http://www.eggheadcafe.com/software/...st-with-c.aspx
<nx*****@winvoi ce.comwrote in message
news:11******** **************@ q75g2000hsh.goo glegroups.com.. .
>Basically it's drawing images next to mycomboBoxitems . Any idea how to
maintain the look that it should, while drawing these images?

I'm having the same issue with Vista, here's the quick code I posted
trying to get help(maybe someone in this group has some better
suggestions).

public class ColoredComboBox : ComboBox
{
public ColoredComboBox ()
{
this.DrawMode = DrawMode.OwnerD rawFixed;
this.DrawItem += new
DrawItemEventHa ndler(ColoredCo mboBox_DrawItem );
}
void ColoredComboBox _DrawItem(objec t sender, DrawItemEventAr gs e)
{
e.DrawBackgroun d();
// don't even care about text, my icon, or anything else at this
point, just want the background to work.
}
}
May 2 '07 #5
If you want to do this you have to handle WM_PAINT and paint the thing
yourself using DrawThemeBackgr ound.
Here's the long explanation of it:
http://www.eggheadcafe.com/software/...dropdown-list-...
Sure would be nice if the shell developers provided some code as an
example of how to work around the situation they put us in. Maybe
then they'd understand and release a patch rather than the hack that
by their own admission may not work on future releases of windows.

The combobox seems to always get the shaft, the project I'm upgrading
was from .NET v1.x and I'm cutting out all the hacks that where put in
place to allow windows 95 style auto-complete to now find that I get
to put in another series of hacks until v3.5 or whenever.

May 2 '07 #6
Here's what I put together over the last few hours of trial and error
and a bunch of searching. I originally was using DrawThemeBackgr ound
and so forth but eventually dumped it and used the easier
VisualStyleRend er's(which are just wrappers, I know, but at least they
are included). Its got a lot of specific stuff to the app I'm using
but should at least give someone a lot of cut-n-paste if they find
this topic in the future.
public class ColoredComboBox : ComboBox
{
#region Private Members
private bool IsVista;
private ComboBoxState cb_State = ComboBoxState.N ormal;
#endregion
#region Public Members
private Image ListaImg1 = null;
public Image ImageData1
{
set
{
ListaImg1 = value;
if (value != null)
{
if (this.DrawMode !=
System.Windows. Forms.DrawMode. OwnerDrawFixed)
{
this.DrawMode =
System.Windows. Forms.DrawMode. OwnerDrawFixed;
if (this.DropDownS tyle !=
ComboBoxStyle.D ropDownList)
this.DropDownSt yle =
ComboBoxStyle.D ropDownList;
}
}
}
get { return (ListaImg1); }
}
private Image ListaImg2 = null;
public Image ImageData2
{
set
{
ListaImg2 = value;
if (value != null)
{
if (this.DrawMode !=
System.Windows. Forms.DrawMode. OwnerDrawFixed)
{
this.DrawMode =
System.Windows. Forms.DrawMode. OwnerDrawFixed;
if (this.DropDownS tyle !=
ComboBoxStyle.D ropDownList)
this.DropDownSt yle =
ComboBoxStyle.D ropDownList;
}
}
}
get { return (ListaImg2); }
}
#endregion
#region Constructor
public ColoredComboBox ()
{
this.SetStyle(C ontrolStyles.Al lPaintingInWmPa int, true);
this.SetStyle(C ontrolStyles.Us erPaint, true);
IsVista = ((Environment.O SVersion.Versio n >= new
Version("6.0.0" )) && (Environment.OS Version.Platfor m ==
PlatformID.Win3 2NT));
this.DropDownSt yle = ComboBoxStyle.D ropDownList;
this.FlatStyle = FlatStyle.Syste m;
this.DrawMode =
System.Windows. Forms.DrawMode. OwnerDrawFixed;
this.DrawItem += new
DrawItemEventHa ndler(ColoredCo mboBox_DrawItem );
}
#endregion
#region DrawIcon
private Rectangle DrawIcon(Graphi cs g,Rectangle r, object
iconData1, object iconData2)
{
Rectangle newBounds = r;
if (iconData2 != null && iconData1 != null)
{
int x = r.X;
int w = this.Height - 4;
newBounds.X += w;
newBounds.Width -= w;
if (iconData2.ToSt ring() == "True" && ImageData2 !=
null) // draw icon
{
w -= 4;
g.DrawImage(Ima geData2, r.X + 1, r.Y + 1, w, w);
}
else if (iconData1.ToSt ring() == "True" && ImageData1 !
= null) // draw icon
{
w -= 4;
g.DrawImage(Ima geData1, r.X + 1, r.Y + 1, w, w);
}
}
return (newBounds);
}
#endregion
#region DrawItem
protected void ColoredComboBox _DrawItem(objec t sender,
DrawItemEventAr gs e)
{
e.DrawBackgroun d();
DrawItemText(e. Graphics, e.Bounds, e.Index);
e.DrawFocusRect angle();
}
private void DrawItemText(Gr aphics g,Rectangle r,int Index)
{
if (Index == -1 || Items.Count == 0)
return;
Color c = ForeColor;
Descriptor d = new Descriptor(Item s[Index].ToString(),
Items[Index].ToString(), null, null, null);
try
{
d = (Descriptor)Ite ms[Index];
if (d.Data3 != null)
c = (Color)d.Data3;
}
catch { }
SolidBrush b = new SolidBrush(c);
g.DrawString(d. Name, this.Font, b, DrawIcon(g,r, d.Data1,
d.Data2));
b.Dispose();
}
private void DrawArrow(Graph ics g, Rectangle rect)
{
Point p1 = new Point(rect.X + 3, rect.Y + rect.Height / 2
- 2);
Point p2 = new Point(rect.X + rect.Width - 3, rect.Y +
rect.Height / 2 - 2);
Point p3 = new Point(rect.X + rect.Width / 2, rect.Y +
rect.Height / 2 + 2);
g.FillPolygon(n ew
SolidBrush(Syst em.Drawing.Syst emColors.Contro lText), new Point[]{p1,
p2, p3});
}
protected override void OnPaint(PaintEv entArgs e)
{
base.OnPaint(e) ;

if (Enabled == false)
cb_State=ComboB oxState.Disable d;
Rectangle r = e.ClipRectangle ;
if (IsVista)
{
PushButtonState pb_State = PushButtonState .Normal;
if (cb_State == ComboBoxState.D isabled)
pb_State = PushButtonState .Disabled;
else if (cb_State == ComboBoxState.H ot)
pb_State = PushButtonState .Hot;
else if (cb_State == ComboBoxState.P ressed)
pb_State = PushButtonState .Pressed;
ButtonRenderer. DrawButton(e.Gr aphics, r,pb_State);
r = new Rectangle(r.Rig ht -
System.Windows. Forms.SystemInf ormation.Vertic alScrollBarWidt h+2,
e.ClipRectangle .Top,
System.Windows. Forms.SystemInf ormation.Vertic alScrollBarWidt h-4,
e.ClipRectangle .Height);
DrawArrow(e.Gra phics, r);
}
else
{
ComboBoxRendere r.DrawTextBox(e .Graphics, r, cb_State);
r = e.ClipRectangle ;
r = new Rectangle(r.Rig ht -
System.Windows. Forms.SystemInf ormation.Vertic alScrollBarWidt h,
e.ClipRectangle .Top,
System.Windows. Forms.SystemInf ormation.Vertic alScrollBarWidt h,
e.ClipRectangle .Height);
ComboBoxRendere r.DrawDropDownB utton(e.Graphic s, r,
cb_State);
}
r = e.ClipRectangle ;
r.Inflate(0, -2);
r.Offset(0, 1);
DrawItemText(e. Graphics,r,Sele ctedIndex);
}
#endregion
#region Mouse Movement
// Draw the smaller pressed button image.
protected override void OnMouseDown(Mou seEventArgs e)
{
base.OnMouseDow n(e);
cb_State = ComboBoxState.P ressed;
Invalidate();
}

// Draw the button in the hot state.
protected override void OnMouseEnter(Ev entArgs e)
{
base.OnMouseEnt er(e);
cb_State = ComboBoxState.H ot;
Invalidate();
}

// Draw the button in the unpressed state.
protected override void OnMouseLeave(Ev entArgs e)
{
base.OnMouseLea ve(e);
cb_State = ComboBoxState.N ormal;
Invalidate();
}

// Draw the button hot if the mouse is released on the
button.
protected override void OnMouseUp(Mouse EventArgs e)
{
base.OnMouseUp( e);
OnMouseEnter(e) ;
}

// Detect when the cursor leaves the button area while
// it is pressed.
protected override void OnMouseMove(Mou seEventArgs e)
{
base.OnMouseMov e(e);

// Detect when the left mouse button is down and
// the cursor has left the pressed button area.
if ((e.Button & MouseButtons.Le ft) == MouseButtons.Le ft &&
!ClientRectangl e.Contains(e.Lo cation) &&
cb_State == ComboBoxState.P ressed)
{
OnMouseLeave(e) ;
}
}

#endregion
}

May 3 '07 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2159
by: Jax | last post by:
I am using a class that inherits from the DataGridTextBoxColumn. It adds a combo box into the column where it displays a selection of choices. The problem I have is that when this comboBox loses focus I lose the selected text. And this next line isn't setting the text in the cell. // code within the custom DataGridComboBoxColumn class this.TextBox.Text = this.ComboBox.SelectedItem.ToString();
1
5962
by: Spurry Moses | last post by:
Hi, I'm converting a project from C++Builder to C# and I just need to copy my class design across. It's looking good so far. To stick with the design I want to inherit from a ComboBox control (ie MyComboBox). I don't need to do anything flash with it, just add a few properties and methods. I'd almost solved this while writing this post but I'll just confirm what I'm doing is OK. It was a bit awkward in Visual Studio because all of...
6
2873
by: dbuchanan | last post by:
VS2005 I've been reading all the help I can on the topic (MSDN, other) but I can't make sense of this. Desired behavior; The user is to choose from the displayed list of the databound combobox and the coresponding 'Id' from the lookup table is to be inserted into the field of the new record. I have two simple tables. "tblPerson" is the data table. The lookup
9
2682
by: salad | last post by:
Due to an earlier posting I read in this newsgroup regarding Office 2007 beta, I downloaded it. After I DL'd it, I got an invitation from MS to get WinVista. I am now wondering if, since both are betas, it is best to buy a new computer? My current computer setup is a Pentium 4, 1 gig memory, 2.66 ghz, 60-80 gig disk drive. MS's requirements for a WinVista computer is A modern processor (800mz)
6
4270
by: j2ee.singh | last post by:
Hi, I'm looking to buy a new laptop primarily to learn & practice .NET and C#. My Question is: Is there any requirement for .NET and C# in terms of the following Operating Systems: - Windows Vista Home Basic - Windows Vista Business
4
5823
by: =?Utf-8?B?Q2FybGFKYWRl?= | last post by:
Can anyone help me? I need to use picture it 2000 every day and use to use it on Windows XP and had NO problems at all. If I would open up windows explorer i could be in my folder that has all of my picture it files in there, .mix files and even though they were not jpegs etc.. windows explorer would show the thumbnail of all of these projects saved so i could quickly look for something and double click to open. Since installing...
10
3283
by: Academia | last post by:
I'm making my own ComboBox and would like the DropDown button to look like the system combo box. Do you know the Font for the "v" that is used in the regular combobox. Is that the letter vee or some other character? I think I can use the system button face color. Is that correct?
2
3250
by: Andrus | last post by:
SWF DataGridView contains combobox control. Activating combobox and pressing F4 to open dropdown menu causes strange NRE (see below). When I enter some valid value to combobox, press tab, shift+tab , 44 dropdown menu opens OK. How to fix ? How to use VCSE 2008 with .net framework source code to find the line in
1
2092
by: Frank van Eijkelenburg | last post by:
Hi, I have to develop an application which must run on .net 2.0 on a Windows XP SP2 and Windows Vista Business OS. Is .net 2.0 supported at Windows Vista? If I see the supported OS at the download page of microsoft, Windows Vista is not in the list. Are there risks for strange behavior under Windows Vista? TIA, Frank
0
8425
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8326
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
8743
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
7355
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...
0
5647
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();...
0
4173
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4333
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2745
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
2
1973
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.