TreeView with custom drawn TreeNode

老子叫甜甜 提交于 2019-12-04 06:25:14

问题


I am trying to add a custom icon near the text of a TreeNode, so the items could have a "checked/unchecked" state displayed. I don't want to use a checkbox for that.

Any ideas? Thanks


回答1:


Assuming you are using .net and Windows Forms.

You must set DrawMode property of TreeView to TreeViewDrawMode.OwnerDrawAll. Once you do this, treeview's DrawNode event will fire each time a tree node is being drawn. Handle that event and draw your items manually.

You will get DrawTreeNodeEventArgs as the event arguments. State property of it will tell you which state of the tree item you must draw. e.Bounds will help you for determining bounds and you can use e.Graphics for drawing. You can find more detailed information here:

http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.drawnode.aspx

But prepare to invest multiple hours.



来源:https://stackoverflow.com/questions/1565072/treeview-with-custom-drawn-treenode

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