Determine Label Size from it's Text property

  • Thread starter Thread starter Mantorok
  • Start date Start date
M

Mantorok

Hi all

Is there anyway of determining the correct size of a label depending on it's
contents? I cannot use AutoSize as that ends up spreading over the edge of
the form, and besides I need this label to be docked also, it is docked to
the Top so the Width will always be automatically sized.

Any ideas? I can't find anything useful in the help.

Thanks
Kev
 
Hi Kev,

You can use Graphics.MeasureString which is usually ok, but not exact, or Graphics.MeasureCharacterRanges which is exact but requires more code.
 
Morten Wennevik said:
Hi Kev,

You can use Graphics.MeasureString which is usually ok, but not exact, or
Graphics.MeasureCharacterRanges which is exact but requires more code.

Spot on, thank you.

Kev
 

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

Back
Top