How to add icons to TreeView control in c# using OnPaint args

爷,独闯天下 提交于 2019-12-12 17:24:13

问题


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.


回答1:


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




回答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.




回答3:


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



来源:https://stackoverflow.com/questions/7249927/how-to-add-icons-to-treeview-control-in-c-sharp-using-onpaint-args

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!