C#的WinForms大胆TreeView节点不显示全文 [英] C# Winforms bold treeview node doesn't show whole text

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

问题描述

我用下面的代码,使我的TreeNode大胆:

I'm using the following code to make my treenodes bold:

Font font = new Font(tvQuestionSequence.Font, FontStyle.Bold);

foreach (QuestionnaireBuilder_Category cat in categories)
{
    TreeNode node = new TreeNode();

    node.Text = cat.Description;
    node.Name = cat.Id.ToString();

    node.NodeFont = font;

    tvQuestionSequence.Nodes.Add(node);
}



但大胆节点的文本无法正确显示。最后一个字母(S)没有显示。怎么来的?而如何解决这个问题?

But the text of the bold nodes is not displayed correctly. The last letter(s) are not shown. How come? And how to solve this problem?

推荐答案

我发现,这是Windows的问题。此问题的解决方法是这样的:

I've found that this is a Windows issue. A workaround for this problem is this:

在表单构造树视图的字体设置为粗体。当添加不可为大胆的节点,改变字体常规:

In the form constructor set the font of the treeview to bold. When adding nodes which must not be bold, change the font to regular:

// Constructor of your form
public Form() 
{
    InitializeComponent();

    Font font = new Font(tvQuestionSequence.Font, FontStyle.Bold);
    tvQuestionSequence.Font = font;
}

// Add regular nodes (not bold)
Font font = new Font(tvQuestionSequence.Font, FontStyle.Regular);

TreeNode treeNode = new TreeNode();
treeNode.Text = "Foo";
treeNode.NodeFont = font;

TreeNode parent = tvQuestionSequence.Nodes.Find("parent", true);
parent.Nodes.Add(treeNode);

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

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