提问者:小点点

温弗斯树视图文本被切断


我在我的通知应用程序中使用树视图。当我用大量文本加载节点时,文本会被切成12个字符。我如何防止这种情况发生?

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

我尝试过使用普通字体,但没有成功。

这是我的代码(我已经用另一个类覆盖了treenode):

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);       
    }

}

}


共3个答案

匿名用户

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

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

匿名用户

当您以编程方式将节点的Font属性设置为Bold值时,节点的文本可能会被截断。

在以编程方式将节点的Font属性设置为Bold值后,您需要向文本添加一个空字符串。

例如:

treeView1.Nodes[0].NodeFont = new System.Drawing.Font("Microsoft Sans Serif", 12pt, System.Drawing.FontStyle.Bold);
treeView1.Nodes[0].Text += string.Empty;

匿名用户

显然我正在裁剪树视图本身内的文本。问题解决了。感谢所有的帮助!