带有格式化文本的 c# Treeview 节点,例如选项卡和标签 新线路

发布于 2024-07-09 06:51:06 字数 129 浏览 15 评论 0原文

是否可以(通过使用库存 c# TreeView)拥有多行 TreeNode?

另外,是否可以向 TreeNode 的文本添加控制字符,例如“\t”? 通过向 TreeNode 添加列也可以实现相同的效果。 这可能吗?

Is it possible (by using the stock c# TreeView) to have Multiline TreeNodes?

Also, is it possible to add control characters to TreeNode's text e.g. '\t'? This same effect could also be achieved by adding columns to the TreeNode. is this possible?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

放我走吧 2024-07-16 06:51:06

我不相信使用 WinForms 可以做到这一点,至少在不绘制自己的节点的情况下是这样。 您也许可以使用“所有者绘制”树节点在 WinForms 中完成此操作,但我不知道。

不过,WPF 本身就支持这一点。

I do not believe this is possible using WinForms, at least without drawing your own nodes. You may be able to use an "owner-drawn" treenode to accomplish this in WinForms, though, I don't know.

This is natively supported with WPF, though.

昨迟人 2024-07-16 06:51:06

从您的问题中并不清楚您是使用 ASP.NET 还是 WinForms。 如果您使用 ASP.NET,您可以尝试使用 PRE 标记来获取格式...?

这就是 Ra-Ajax TreeView 的意思,您可以在此处查看 的示例 可以包含任意数量的 HTML 和/或什至其中的控件,这在很大程度上使其优于 ASP.NET 中内置的 TreeView。 (免责声明;我使用 Ra-Ajax)

这使您可以完全按照您的意愿格式化 TreeView 的内容。 不过,如果你完全发疯,你仍然面临着由于空间太大或类似的原因而创建“显示伪影”的风险......

It isn't very clear from your question whether you are on ASP.NET or WinForms. If you're in ASP.NET you could try using the PRE tag to get formatting...?

What that's said the Ra-Ajax TreeView which you can see an example of here can have any arbitrage amount of HTML and/or even controls within it which mostly makes it way superior to the built in TreeView in ASP.NET. (Disclaimer; I Work with Ra-Ajax)

This makes it possible for you to format the contents of the TreeView exactly as you wish. Though if you go completely berserk you still run the risk of creating "display artifacts" due to too much space or something like that...

夏の忆 2024-07-16 06:51:06

在 TreeNode 中不可能有效地使用制表符。
无论如何,我有一个解决方法:

字体“Consolas”每个字母的间距相等,因此您可以轻松地用空格分隔。 GetEmptyInfoByIndex 方法返回一个自定义长度的空格字符串来填充间隙,直到达到指定的长度。 这里 = 20。

mynode.NodeFont = new System.Drawing.Font("Consolas", 9,FontStyle.Regular);

string displaytext = String.Format(CultureInfo.InvariantCulture, "{0}{2} = {1}", mystringOfDifferentLenght, myresult, GetEmptyInfoByIndex(mystringOfDifferentLength, 20));
mynode.Text = displaytext;
rootnode.Nodes.Add(mynode);

private string GetEmptyInfoByIndex(string _string, int maxLength)
    {
        string retstr = string.Empty;
        for (int i = 0; i < maxLength - _string.Length; i++)
        {
            retstr += " ";
        }
        return retstr;
    }

证明在这里!

It is not possible to use the tabulator effectively inside a TreeNode.
Anyways, I have a workaround:

The Font "Consolas" has equal space of each letter so you can space easily with blanks. The method GetEmptyInfoByIndex returns a custom lenght string of spaces to fill the gap until a specified length. Here = 20.

mynode.NodeFont = new System.Drawing.Font("Consolas", 9,FontStyle.Regular);

string displaytext = String.Format(CultureInfo.InvariantCulture, "{0}{2} = {1}", mystringOfDifferentLenght, myresult, GetEmptyInfoByIndex(mystringOfDifferentLength, 20));
mynode.Text = displaytext;
rootnode.Nodes.Add(mynode);

private string GetEmptyInfoByIndex(string _string, int maxLength)
    {
        string retstr = string.Empty;
        for (int i = 0; i < maxLength - _string.Length; i++)
        {
            retstr += " ";
        }
        return retstr;
    }

Proof here!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文