C#中的TreeView节点AutoEllipsis属性 [英] TreeView Node AutoEllipsis property in C#

查看:121
本文介绍了C#中的TreeView节点AutoEllipsis属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个树视图控件,其中包含一些节点.我希望自动省略号"属性像标签控件一样具有树视图节点.我使用过Google,但没有获得相关信息或方法来完成此任务.
我正在使用c#作为编程语言,并使用.net framework 3.5作为平台.我在Windows窗体中而不是WPF中制作程序.
谢谢.

I have a tree view control which has some nodes. I want Auto Ellipsis property to tree view node as like label control have. I did Google but not get relevant information or method to achieve this task.
I am using c# as a programing language and .net framework 3.5 as a platform. I am making program in windows form not in WPF.
Thanks.

推荐答案

在标准WinForms TreeView控件中,实现此目标很复杂,我怀疑您对性能或结果不满意. TreeView包含大量节点.

是的,我已经实现了与WinForms TreeView类似的东西,并且不再使用它:使用和维护这是一个很痛苦的事情,并且使用大量Node的性能并不令人满意.

像您在这里描述的那样,缺乏设施是促使我几年前研究3rd的原因.最终,我最终从Lidor Systems购买了IntegralUI TreeView,这是我强烈推荐的,并且在过去几年中以各种方式取得了显着的发展,并伴随着一流的高响应技术支持. br/>
尽管我刚才提到的功能是:我选择了出色的IntegralUI TreeView的次要原因之一,该功能的恕我直言使WinForms TreeView看起来像是:难以使用,性能非常有限的玩具".这是围绕"COM古董"的.NET包装.而且,不,我不为Lidor工作! :)

这里是一些要考虑的事实":重新使用标准WinForms TreeView

1.您无法将控件添加到节点(可以在IntegralUI TV中添加).

2.您可以将控件(如Label)添加到TreeView.Controls ControlCollection本身,是的,您可以基于Mouse(鼠标)所在,正在移动或正在悬停的位置来移动它,但有一些重要限制.将标签直接添加到TreeView的优点:Label坐标空间位于TreeView坐标空间中.缺点:Label的宽度将由TreeView的宽度确定.

3.最简单的想法也许是在Form本身上添加一个具有透明背景的Label,然后做正确的事以将其用作弹出其文本为Ellipsis的Node的弹出窗口:这将涉及到一些复杂的转换.节点边界框​​空间(在TreeView坐标中)到标签位置(在表单坐标中).优点:标签宽度可以根据需要而定.缺点:就像刚才提到的那样,复杂的坐标转换.

4.然后,考虑到您有大量的节点:对于这些节点中的每个节点,您都将需要处理节点中可见的文本条目的可变大小:您将需要修剪"文本,并添加文本.根据节点边界框​​的宽度,在右边的省略号...:文本的可用宽度的范围将随着嵌套的每个级别的左边界变大而变化.

...现在想想如果调整TreeView的大小就必须重新做一遍!

...现在考虑一下支持水平滚动的TreeView!您是否要增长"节点文本的可见部分并在每次水平滚动时动态调整Ellipsis:imho:如果您神智正常,就不会:)

要实现上述任何一项,您要么必须保留所有节点的扁平化"列表,要么每次您需要调整所有节点中显示的文本时递归解析整个TreeView(使用IntegralUI TreeView扁平化,始终是最新的) ,NodeList是提供的功能).

5.现在考虑您要以其他方式模拟"标签控件的省略号自动扩展行为:

一个.您可以尝试使用工具提示:相信我,您将不会满意,并且每个节点使用一个工具提示的想法也很::请:甚至不要想像它:)

b.或者,回到您将Label直接添加到TreeView的想法(请参阅上面的#2).

1.您可以尝试为TreeView处理NodeMouseHover事件,并计算鼠标所在节点的位置,然后尝试移动Label,使其恰好位于Node中正常显示的Text上,然后...

一个.相信我,您会发现使用悬停事件一直令人沮丧.

b.如果单击Label ...(现在位于Node之上),以模拟被单击的Node,则需要做一些事情:这并不难.

总之,我的拙见是,在WinForms TreeView中模拟Label的很好的Ellipsis自动扩展功能不是一个好主意:成本远远超过了任何小的GUI/UX收益.
In the standard WinForms TreeView Control achieving this is going to be complex, and I suspect, that you will not be satisfied with performance, or results when the TreeView contains a large number of nodes.

Yes, I have implemented something similar with the WinForms TreeView, and don''t use it anymore: it was a pain-in-the-rear to use and maintain, and performance with large number of Nodes was not satisfactory.

Lack of facilities, like what you describe here, are what motivated me, years ago, to research 3rd. party TreeView components, and I ended up purchasing the IntegralUI TreeView from Lidor Systems, which I highly recommend, and which has evolved remarkably in every way over the last few years, and is accompanied by first-class highly-responsive technical-support.

Although the feature I just mentioned was: one of the less important reasons I chose the remarkable IntegralUI TreeView, whose functionality, imho, makes the WinForms TreeView seem like what it is: a hard-to-use, very limited performance, "toy" which is a .NET wrapper around a "COM Antique." And, no I do not work for Lidor ! :)

Here''s some "facts" to consider: re standard WinForms TreeView

1. You cannot add Controls to a Node (in the IntegralUI TV you can).

2. You can add a Control, like a Label, to the TreeView.Controls ControlCollection itself, and yes, you can move it around based on where the Mouse is, or is moving, or is hovering ... with some important limitations. The advantage of adding a Label directly to the TreeView: Label co-ordinate space is in TreeView co-ordinate space. Disadvantage: the Label width is going to be determined by the TreeView width.

3. The simplest idea, perhaps, is adding a Label with transparent background to the Form itself, and then doing the right thing to use it as a pop-up over the Node whose Text has the Ellipsis: that will involve some complex transformations from Node Bounding Box space (which is in TreeView co-ordinates) to Label Location which is in Form co-ordinates. Advantage: Label width can be as long as you need. Disadvantage: complex co-ordinate transforms, as just mentioned.

4. Then, consider you have a very large number of Nodes: for everyone of those Nodes you will need to deal with the variable size of the Text entry visible in the Node: you will need to "trim" the text, and add the Ellipsis at the right place ... depending on the width of the Node bounding box: the extent of the available width for the Text ... is going to vary as the left margin gets larger for each level of nesting.

... And now think about having to do that all over again if the TreeView is resized !

... And now think about the TreeView supporting horizontal scrolling ! Are you going to "grow" your visible portion of Node Text and adjust Ellipsis dynamically with every horizontal scroll: imho: if you are sane you will not :)

To achieve any of the above you are going to either have to keep a "flattened" list of all Nodes, or recursively parse the whole TreeView every time you need to adjust the Text displayed in all Nodes (with IntegralUI TreeView a flattened, always current, NodeList is a provided feature).

5. Now consider you want to "simulate" the Label Control''s Ellipsis auto-expand behavior in other ways:

a. you could try using a ToolTip: you will fail to find that satisfactory, believe me, and the idea of using one ToolTip per Node : please: don''t even imagine it :)

b. or, going back to the idea you added a Label directly to the TreeView (see #2 above).

1. you can try handling the NodeMouseHover Event for the TreeView, and calculating the position of the Node the Mouse is over, then try moving the Label so it fits just over the normally displayed Text in the Node ... and then ...

a. You are going to find using the Hover Event consistently frustrating, believe me.

b. You will need to do something if the Label ... now over the Node ... is clicked to simulate the Node being clicked: that''s not hard to do.

In conclusion, it''s my humble opinion that simulating the very nice Ellipsis auto-expand feature of a Label in a WinForms TreeView is not a good idea: the costs far outweigh any small GUI/UX benefits.


这篇关于C#中的TreeView节点AutoEllipsis属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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