How can I change the expand/collapse images from the plus ( + ) and minus ( - ) images that appear when ShowPlusMinus
and/or ShowRootLines
are true
.
To help visualize, I would like to make the following TreeView
Look like this (like Windows explorer)
Expanding on Ivan Ičin's solution :
To use, add a
TreeView
to your form, and inForm_Load
:Alternatively, you can extend the TreeView object
SetWindowTheme
There are 3 methods I can think of:
Sunny already mentioned using
SetWindowTheme(TreeView.Handle, "explorer", null)
Using WPF if that is the option and adding TreeViewItem object
Overriding OnPaint methods, which is too complicated, considering you can do just 1, so 1 or 2 it is up to you to chose.
When you want to customize your treeview control, Microsoft provides a property named "TreeViewDrawMode" on the treeview control, it's value is a enum which has 3 values:Normal, OwnerDrawText, OwnerDrawAll, in your situation, you must use OwnerDrawAll. after you set that property as OwnerDrawAll, when the treeview's nodes are showing, a event named "DrawNode" will be triggered, so you can process your drawing there. when you draw it by yourself, usually you need to draw 3 things: expand/collapse icon, node icon, node text. my sample is below: //define the icon file path string minusPath = Application.StartupPath + Path.DirectorySeparatorChar + "minus.png"; string plusPath = Application.StartupPath + Path.DirectorySeparatorChar + "plus.png"; string nodePath = Application.StartupPath + Path.DirectorySeparatorChar + "directory.png";
the result of my test is like this:![picture of result](https://i.stack.imgur.com/3cmlY.jpg)