Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Textwidth Method

Status
Not open for further replies.

enigma333

Programmer
Jul 3, 2001
42
CA
I need to determine the width of a string as displayed on the screen....
i.e. the number of twips it takes to display ... must show correct for font & fontweight.

Textwidth alone gives inconsistent value

Any Thoughts...

Basically i want a label to autosize to contents and account for changes in font size , type , and weight

Thanks
 
TextWidth and TextHeight are methods of the Form. Therefore if you want to apply them to a Label, you first must assign the Label's Font.Name and Font.Size to the Form and then ask for the TextWidth to evaluate your text's properties. Unfortunately, this will have some undesired effects on your form's appearance (unless you use the same font).

These methods are primarily useful to "Print" your text directly on the Form, without the use of Labels. Printis one of the less used Drawing methods (like Line, Circle, ...). If you do not intend to use any of your Label's Events, then this method could provide an alternative.

Also, be aware that these methods are only "perfect" with non-proportional fonts. For proportional fonts they calculate the size based on an estimated average character size, which does take into account a normal distribution of the characters in a (English) text.

Conclusion: John's suggestion is by far the easiest alternative
_________________________________
In theory, there is no difference between theory and practice. In practice, there is. [attributed to Yogi Berra]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top