VisualStyleRenderer and themes (WinForms)

Posted by Yves on Stack Overflow See other posts from Stack Overflow or by Yves
Published on 2010-06-10T13:31:17Z Indexed on 2010/06/11 21:02 UTC
Read the original article Hit count: 967

Filed under:
|

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!

© Stack Overflow or respective owner

Related posts about .NET

Related posts about winforms