VisualStyleRenderer and themes (WinForms)
- by Yves
I have my own TreeView control which is completely OwnerDraw'ed:
myTreeView.DrawMode = TreeViewDrawMode.OwnerDrawAll;
What I try to achieve is to draw the opened/closed glyph according to the current explorer theme. Especially on Vista and Win7 boxes I'd like to see the new glyphes (black triangles) instead of the plus/minus signs. I know, for a non-OwnerDraw'ed TreeView this can be achieved as follows which works perfectly:
myTreeView.HandleCreated += delegate(object sender, EventArgs args)
{
MyNativeMethods.SetWindowTheme(myTreeView.Handle, "explorer", null);
};
I thought a VisualStyleRenderer let me paint the glyphs theme-aware:
VisualStyleRenderer r = new VisualStyleRenderer(VisualStyleElement.TreeView.Glyph.Opened);
r.DrawBackground(e.Graphics, e.Bounds);
The code above unfortunately draws the minus sign in all cases. It looks like the VisualStyleRenderer does not honour the theme setting.
Can someone shed some light on this? Thanks!