TreeNode.NodeFont problem

Crono

Newcomer
Joined
Dec 9, 2002
Messages
6
I'm populating a TreeView control at run-time and I want my first-level nodes to be in bold text. When I change font via TreeNode.NodeFont, the node isn't resized to fit with the new text size and it appears only partialy.

I know I could change the width of the node, but it won't fit to the text. Isn't there any other way?
 
This is a known problem and has to do with GDI+ and clipping.

The only solution that works is to change the Font of the treeview itself to bold, and then each node added that is NOT bold changed to reflect that as you add it.
 
You should not have to reverse the font for the tree as suggested....

I got it to work by first setting the font, then setting the text - something like the code snippet below:

Code:
public void SetNodeFont(TreeNode node, Font font)
{
   // First set the new font for the node.
   node.NodeFont = font;
   // Set the text again - forces the bounding box
   // of the node to be set around the text using
   // the new font.
   node.Text = node.Text;
}

Rgds, Willem
 
Back
Top