How do I calculate neccessary label size

  • Thread starter Thread starter Thore Berntsen
  • Start date Start date
T

Thore Berntsen

Say I have a label on a from, and I put some text in it. How do I calculate
the needed size (width and height) of this label so that the whole text is
shown?

Thore Berntsen
 
a simple solution to use a font with all the char has the same width like
"courrier new" (don't know the english name of the font)
then a simple calcul on the text.len gives the with.

int OneCharWidth = 8; // 8pixels
myLabel.width = (myLabel.text.len + 1)* (OneCharWidth );

It is not very ellegant, but simple and it works :)

hopes that's help.
 
Back
Top