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?
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.
Sounds like you might need to look at System.Windows.Forms.VisualStyles.VisualStyleRenderer:
The
System.Windows.Forms.VisualStyles
namespace exposesVisualStyleElement
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 aVisualStyleRenderer
to the element you are interested in.To draw an element, use the
DrawBackground
method. TheVisualStyleRenderer
class also includes methods, such asGetColor
andGetEnumValue
, 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.