开发者

TreeView with custom drawn TreeNode

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

Any ideas? Thanks


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜