NodeFont change results in truncated text (bug in .NET Framework)

  • Thread starter Thread starter Jon Davis
  • Start date Start date
J

Jon Davis

Seems that there's a bug in the TreeNode object. When you change the font,
it does not readjust its size appropriately.

The following code shows the boldface text truncated with everything after
"W" removed.

private void Form1_Load(object sender, System.EventArgs e) {
TreeNode newNode = new TreeNode("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
treeView1.Nodes.Add(newNode);
newNode = new TreeNode("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
newNode.NodeFont = new Font(this.Font, FontStyle.Bold);
treeView2.Nodes.Add(newNode);
}

What I want to know is, how do I work around this? I need some of the nodes
to be in bold!

Thanks,
Jon
 
Hi Jon,

I agree this *looks* as a bug, but I believe this behavior is documented in
MSDN that warns the text *will* be truncated if the node font is larger than
the tree font. The trick I've used was to set the base tree font to bold,
and reset the boldness flag on all nodes that didn't need to be rendered in
bold face.

P.S. Dirty hack, I know :-)
 
Thank you. That makes it a documented bug, but still a bug. But the
workaround should work. Thanks.

Jon


Dmitriy Lapshin said:
Hi Jon,

I agree this *looks* as a bug, but I believe this behavior is documented in
MSDN that warns the text *will* be truncated if the node font is larger than
the tree font. The trick I've used was to set the base tree font to bold,
and reset the boldness flag on all nodes that didn't need to be rendered in
bold face.

P.S. Dirty hack, I know :-)

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Jon Davis said:
Seems that there's a bug in the TreeNode object. When you change the font,
it does not readjust its size appropriately.

The following code shows the boldface text truncated with everything after
"W" removed.

private void Form1_Load(object sender, System.EventArgs e) {
TreeNode newNode = new TreeNode("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
treeView1.Nodes.Add(newNode);
newNode = new TreeNode("ABCDEFGHIJKLMNOPQRSTUVWXYZ");
newNode.NodeFont = new Font(this.Font, FontStyle.Bold);
treeView2.Nodes.Add(newNode);
}

What I want to know is, how do I work around this? I need some of the nodes
to be in bold!

Thanks,
Jon
 
Back
Top