自定义TreeNode范围 [英] Custom TreeNode bounds

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

问题描述

如何在更大的节点区域上扩展TreeView节点的标准鼠标行为(如选择,热跟踪,双击扩展等)?我有一个自定义绘制的节点,其标签具有比系统绘制的标签更宽的标签,并且仅当光标位于普通节点的边界内时,它才会对鼠标动作做出反应.

How to extend the standard mouse behavior of a TreeView node (like selecting, hot tracking, expansion on double click etc.) over a wider node area? I've got a custom-drawn node that has a wider label than it would have if it was system-drawn and it only reacts to mouse actions when the cursor is within the ordinary node bounds.

有什么想法吗?

顺便说一句,拦截TVM_GETITEMRECT和TVM_HITTEST不会成功.

BTW, intercepting TVM_GETITEMRECT and TVM_HITTEST won't do the trick.

关于我在做什么的几句话:我正在开发一个WinForms树控件,该控件通常与WinForms TreeView完全一样,但是还允许添加特殊的节点,这些节点可以将自定义字体和颜色应用于自定义字体和颜色.他们的标签.因此,有点"RichTreeView",例如可以使节点的文本中带有加粗的单个单词.通过对字体进行一些粗大的修改,节点标签可以比常规标签更宽,但也更窄(这会导致另一个抑制鼠标动作的问题),因此是我的问题.

A few words about what I'm doing: I'm developing a WinForms tree control that normally acts exactly the same as WinForms TreeView, but also allows for adding special nodes that can have custom fonts and colors applied to any parts of their labels. So it's kinda "RichTreeView" that can for example have nodes with bolded single words in their text. With some heavy font tinkering a node label can get way wider than regular, but also narrower (which causes another problem of suppressing mouse actions), hence my question.

推荐答案

是的,这是本机Windows控件的问题.它没有任何指定自定义项目范围的方法.TVN_GETDISPINFO通知可能是最接近的,但是NMTVDISPINFO缺少指定边界的方法..NET包装器没有实现它.实在只足以实现VirtualMode.

Yes, this is a problem with the native Windows control. It doesn't have any way to specify a custom item bounds. The TVN_GETDISPINFO notification is probably closest, but NMTVDISPINFO is missing a way to specify the bounds. The .NET wrapper doesn't implement it. It is really only good enough to implement a VirtualMode.

根据原始指标继续进行命中测试和TreeNode.Bounds.水平滚动条尤其是一个问题,如果滚动条比原始文本宽,滚动条滚动得不够远,无法显示所有自定义绘制的文本.您可以通过实现MouseDown并迭代TreeNode.Bounds属性来解决命中测试问题,而不是滚动条问题.

That keeps hit testing and TreeNode.Bounds based on the original metrics. It is especially a problem with the horizontal scrollbar, it won't scroll far enough to reveal all the custom-drawn text if it is wider than the original. You can somewhat solve the hit testing problem by implementing MouseDown and iterating the TreeNode.Bounds properties but not the scrollbar problem.

目前尚无明确的解决方案,只有一个难看的解决方案.将TreeNode.Text设置为足以解决问题的任意字符串.如有必要,可以使用Tag属性存储实际文本.这取决于您绘制的自定义方式,在Text前面加上几个M可能就足够了.不漂亮.

There's no clean fix for this, only an fugly one. Set the TreeNode.Text to an arbitrary string that's wide enough to solve the problem. You could use the Tag property to store the actual text, if necessary. It depends on how custom you draw, prefixing the Text with a couple of M's might be good enough. Not pretty.

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

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