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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

width of a string

Status
Not open for further replies.

aidanh

Programmer
Aug 14, 2003
9
GB
if I have a string x = "hello"
and I know the font face is "Arial"
and the size is 25

how can I find out the width of the string ( not the number of characters, but the width in pixels )

does anyone know?

thx

aidanh
 
The width of a string depends upon the object in which you display it.
VB provides a function called .TEXTWIDTH which applies to forms and pictureboxes (for example)

The result changes according to:
The scalemode of the object
The font in question AT THE TIME YOU ASK
The display settings.

So, briefly, set the form's font to Arial 8, set the scalemode of the form to PIXELS, and get the result of
Form1.textwidth("Hello")

This get more complex if the string is long and expected to word wrap...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top