c# - Winforms Treeview 文本被截断

标签 c# winforms treeview

我在通知应用程序中使用 TreeView 。当我加载包含大量文本的节点时,文本被截断为 12 个字符。我该如何避免这种情况发生?

正在使用的字体: Microsoft Sans Serif, 12pt, style=Bold

我曾尝试使用纯字体,但没有成功。

这是我的代码(我用另一个类覆盖了树节点):

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Diagnostics;

namespace Repetrel
{
    public class ActionObjectTreeNode: TreeNode
    {
    public string fileName = null;

    private ActionObject actionObject = new ActionObject();

    public string Text {
        get { return base.Text; }
        set {
            if (value.Equals(base.Text) == false && base.Text!="")
            {
                Trace.WriteLine("error detected");
            }
            base.Text = value;
        }
    }

    public ActionObject ACTIONOBJECT
    {
        get
        {
            return actionObject;
        }

        set
        {
            actionObject = value;
            if (value == null && TREENODETYPE != TreeNodeType.Project) {
                System.Diagnostics.Trace.WriteLine("null assigned to actionobject");
            }
        }
    }
    public TreeNodeType TREENODETYPE { get; set; }
    public TreeNodeType LOCKEDNODETYPE { get; set; }
    public DrillActionGroup ACTIONPROPERTIES { get; set; }

    public ActionObjectTreeNode()
    {

    }

    public ActionObjectTreeNode(string text)
    {
        this.Text = text;
    }

    public ActionObjectTreeNode(ActionObject actionObject)
    {
        if (actionObject != null)
        {
            this.Text = actionObject.TEXT;
            this.ACTIONOBJECT = actionObject;
        }
    }


    public bool guidMatch(string _guid)
    {
        return ACTIONOBJECT.getGuid().Equals(_guid);       
    }

}

最佳答案

将 TreeView 的字体大小属性值设置为高于您以编程方式设置的字体大小。

(image) Microsoft Help

(image) The Font property value of the treeview

https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.treenode.nodefont?view=netframework-4.8

关于c# - Winforms Treeview 文本被截断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33288606/

相关文章:

c# - 检测 Excel 文件是否已关闭

c# - 有什么理由不将 pdb 与您的应用程序一起提供吗?

c# - ComboBox 在键入时更改文本颜色的事件

php - 如何使用 getAllChecked() 获取 dhtmlx 中检查的项目的文本

c# - Moq:在对不返回值的方法进行方法调用后回调

c# - BitmapData.Stride 与 GetPixelFormatSize(BitmapData.PixelFormat) 除以 8

c# - 将 MySQl 'YYYY-MM-DD' 转换为 .Net DateTimePicker

c# - 在线ClickOnce部署应用程序并在桌面/开始菜单上放置一个图标

回发前的 ASP.NET TreeView javascript

c# - 如何在 asp.net TreeView 中的树节点中存储数组数据