views:

1118

answers:

2

I can draw a 3D border using ControlPaint.DrawBorder3D, but I get the 'Windows Classic' 3D border. I want to draw the current theme's 3D border - in the default XP theme, this is a 1px blue or gray border. How do I draw that, and how do I get its widths?

+1  A: 

Pre .NET Framework 2.0 Answer

I'm assuming that you are drawing your own, special control and you want to use elements of the currently active theme to draw it so it better fits with standard XP controls. You're NOT trying to, for example, enable theming on a standard Button control. Correct?

It's actually somewhat complicated. Your main focus should be UxTheme.dll. This houses everything you need for drawing themed controls. Here is a nice C# wrapper around this dll to make your life easier. There are others so if this isn't exactly what you wanted, I hope I've pointed you in the right direction.

colithium
+4  A: 

Sounds like you might need to look at System.Windows.Forms.VisualStyles.VisualStyleRenderer:

The System.Windows.Forms.VisualStyles namespace exposes VisualStyleElement objects that represent all of the controls and user interface (UI) elements that are supported by visual styles. To draw or get information about a particular element, you must set a VisualStyleRenderer to the element you are interested in.

To draw an element, use the DrawBackground method. The VisualStyleRenderer class also includes methods, such as GetColor and GetEnumValue, that provide information about how an element is defined by the current visual style.

There's a code sample on that page as well.

You will have to draw the border yourself, but you can get the color from VisualStyleElement.Window.Caption.Active and the size should be the size of the window frame (I believe), which is VisualStyleElement.Window.FrameBottom.Active. If you explore the VisualStyleElement.Window, you should be able to determine which window element has the information you need to draw your border.

Factor Mystic
Is this new to 2008 (he didn't specify which version he was using, just wondering)
colithium
Hmm, it came about with 2.0. Much easier (if he's using at least 2.0) +1
colithium
Which VisualStyleElement do I need? None of them look right to me.
Simon