TreeView with custom drawn TreeNode

前端 未结 1 1579
刺人心
刺人心 2021-01-27 07:49

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.

1条回答
  •  清歌不尽
    2021-01-27 08:08

    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 讨论(0)
提交回复
热议问题