TreeView node in bold has incorrect length

M

Marcel Brekelmans

Hi,

When I set the text of a TreeView node to bold (or Italic for that matter)
programmatically, it doesn't show up with its length adjusted. Instead, it
has the length of the text in normal font, so it is clipped at the end. Does
anyone know of a workaround?

Thanks
 
M

Michael A. Covington

Marcel Brekelmans said:
Hi,

When I set the text of a TreeView node to bold (or Italic for that matter)
programmatically, it doesn't show up with its length adjusted. Instead, it
has the length of the text in normal font, so it is clipped at the end.
Does anyone know of a workaround?

Thanks


Not exactly, but try changing the font of the TreeView from "MS Sans Serif"
to Tahoma. In fact, do that to your whole form and make sure the TreeView
inherits it. "MS Sans Serif" is the default font of older .NET versions and
is a flawed font -- I have had other problems with its spacing and width.

See this:
http://www.covingtoninnovations.com/michael/blog/0603/index.html#060312
 
M

Marcel Brekelmans

Hi Michael,

I tried your solution. Unfortunately, it doesn't help: the textlength is
still based on the 'Normal' font.

However, I came across another approach which does a good job: make the font
of the TreeView Bold in the constructor. For each TreeNode you add, make its
font Normal. That way, the length of the TreeNode.Text is based on the Bold
font and when you make it actually bold it is not clipped.

Thanks anyway.
 
F

Frans Bouma [C# MVP]

Marcel said:
Hi,

When I set the text of a TreeView node to bold (or Italic for that
matter) programmatically, it doesn't show up with its length
adjusted. Instead, it has the length of the text in normal font, so
it is clipped at the end. Does anyone know of a workaround?

This is an issue in windows. I ran into this as well some time ago and
decided to go with an alternative color instead. The workaround, which
you probably won't like, is to set all texts to bold initially and then
programmatically set every node's text which has to be normal looking
to normal font.

If I'm not mistaken, Raymond Chen (The 'OldNewThing' blog) blogged
about the reason for this some time ago, but I can't find the exact
link. What I do know is that it's an issue in windows.

FB

--
------------------------------------------------------------------------
Lead developer of LLBLGen Pro, the productive O/R mapper for .NET
LLBLGen Pro website: http://www.llblgen.com
My .NET blog: http://weblogs.asp.net/fbouma
Microsoft MVP (C#)
------------------------------------------------------------------------
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top