带有自定义绘制 TreeNode 的 TreeView [英] TreeView with custom drawn TreeNode

查看:36
本文介绍了带有自定义绘制 TreeNode 的 TreeView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 TreeNode 的文本附近添加一个自定义图标,以便项目可以显示已选中/未选中"状态.我不想为此使用复选框.

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.

有什么想法吗?谢谢

推荐答案

假设您使用的是 .net 和 Windows 窗体.

Assuming you are using .net and Windows Forms.

必须将 TreeView 的 DrawMode 属性设置为 TreeViewDrawMode.OwnerDrawAll.执行此操作后,每次绘制树节点时都会触发 treeview 的 DrawNode 事件.处理该事件并手动绘制您的项目.

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.

您将获得 DrawTreeNodeEventArgs 作为事件参数.它的 State 属性会告诉您必须绘制树项的哪个状态.e.Bounds 将帮助您确定边界,您可以使用 e.Graphics 进行绘图.您可以在此处找到更多详细信息:

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

但准备投入多个小时.

这篇关于带有自定义绘制 TreeNode 的 TreeView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆