如何使用 OnPaint args 在 C# 中向 TreeView 控件添加图标
如何在没有 ImageList 控件的情况下向 C# 中的 TreeView 控件添加图标?我认为您需要调用 OnPaint 事件参数,但不知道如何执行。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
你必须编写 OwnerDraw 控件的代码。除非您没有真正严肃的原因,否则请避免这种情况,因为如果您想以一种好的方式做到这一点,这可能会变成非常复杂的场景。
看看这个例子。
DrawNode 事件
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
您可以覆盖
OnDrawNode()
并将
DrawMode
设置为TreeViewDrawMode.OwnerDrawAll
。但是,您很快就会意识到模拟默认树视图的确切行为几乎是不可能的。有一些状态是由控件私下保存的,如果不进行大量的操作,您就无法访问它们。例如,在标准树视图控件上,在节点上按鼠标按钮而不释放它,将在树视图控件将其注册为选定节点之前将该节点显示为选定状态。尝试模拟使用所有者绘制的节点非常困难,基本上需要您重新实现整个过程。
You can override
OnDrawNode()
and setDrawMode
toTreeViewDrawMode.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.
有很多关于如何进行 TreeView 节点所有者绘图的示例:
C#:TreeView所有者使用ownerdrawtext进行绘制,并且单击节点时会出现奇怪的黑色突出显示
选择时TreeView所有者绘制故障
http://www.codeproject.com/KB/cpp/CustomDrawTreeview.aspx
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