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
 
Back
Top