Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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?

  • *Gurus*
Posted

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.

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

  • 5 years later...
Posted

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:

 

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

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...