2

How to add icons to TreeView control in c# WITHOUT the ImageList control? I think you need tp call the OnPaint event args but no idea how to do it.

user532104
  • 1,373
  • 6
  • 17
  • 27

3 Answers3

3

Yo have to code OwnerDraw control. Unless you have not really serious reasons, avoid this, as this can turn out into very complicated scenarios, if you want to do it in a good way.

Have a look on this example.

DrawNode event

Tigran
  • 61,654
  • 8
  • 86
  • 123
2

You can override OnDrawNode() and set DrawMode to TreeViewDrawMode.OwnerDrawAll. However, you will soon realise that emulating the exact behaviour of the default tree view is almost impossible. There are some state kept privately by the control that you can't access without a lot of fiddling.

For instance, on a standard tree view control, pressing the mouse button over a node without releasing it will show the node as selected before it's been registered as selected by the treeview control. Trying to emulate that using owner drawn nodes is very hard and basically requires you to reimplement the whole thing.

Coincoin
  • 27,880
  • 7
  • 55
  • 76
1

there are many example on how to do TreeView's nodes owner drawing:

C#: TreeView owner drawing with ownerdrawtext and the weird black highlighting when clicking on a node

TreeView owner draw glitch when selecting

http://www.codeproject.com/KB/cpp/CustomDrawTreeview.aspx

Community
  • 1
  • 1
Davide Piras
  • 43,984
  • 10
  • 98
  • 147