views:

321

answers:

1

I have a ComboBox that I have set DrawMode = DrawMode.OwnerDrawFixed. Then I handle the OnDrawItem event and everything works perfectly. However, it looks very different from a standard ComboBox because mine doesn't seem to be rendered using VisualStyles. Do I need to do something to specifically enable VisualStyle rendering for my owner drawn control? I have tried SetWindowTheme on my control, but I'm not sure what theme class to send. Any help would be much appreciated. Thanks!

+4  A: 

The down side of owner-draw is that when you turn it on, the owner (you) has to draw everything. You are almost completely on your own.

If you want visual styles, then you have to call the VisualStyles APIs directly to do what you want. If you want to show selected, focussed, enabled/disabled states, then you have to write code to deal with them all.

This isn't a direct answer for your combo-box issues, but as an example of how to use VisualStyles, here is how I've used VisualStyles in an owner-drawn TreeView to draw the Plus/Minus icon:

// Draw Expand (plus/minus) icon if required
if (ShowPlusMinus && e.Node.Nodes.Count > 0)
{
 // Use the VisualStyles renderer to use the proper OS-defined glyphs
 Rectangle expandRect = new Rectangle(iconLeft-1, midY - 7, 16, 16);

 VisualStyleElement element = (e.Node.IsExpanded) ? VisualStyleElement.TreeView.Glyph.Opened
              : VisualStyleElement.TreeView.Glyph.Closed;

 VisualStyleRenderer renderer = new VisualStyleRenderer(element);
   renderer.DrawBackground(e.Graphics, expandRect);
}
Jason Williams
I've tried to use the VisualStyleRenderer to draw the part, but the only VisualStyleElement I can find is the ComboBox.Button. I'll investigate this some more, or just give up and make them all un-styled. :)
Jon Tackabury