text width of a string at a certain font size

  • Thread starter Thread starter ray well
  • Start date Start date
R

ray well

hi,

in order to place a string of text at a specific place on a printed page, i
need to know its width in pixels at a certain font size. in vb6 there used
to be a function something like 'TextWidth' to which you would feed a string
and get its width.

how can i do this in vb net?

thanks

ray

please respond to the list
 
have a look at system.drawing...specifically the RectangleF arg of the
DrawString method.

hth,

steve
 
Hi Ray,

The 'TextWidth' equivalent in .NET is called MeasureString and it's a
member of the Graphics class. You may find, however, that using DrawString in
the manner that Steve suggests, means not needing to be concerned about the
width.

Regards,
Fergus
 
Just to clarify a bit.

Using DrawString with the RectangleF argument causes the string to wrap to
the bounds specified in the Rectangle. Using drawstring with X, Y
coordinates will draw it across the page until it runs out of text.

If you're just trying to layout some text on a surface or a printdocument,
and the font is fixed, check out our product, GDI+ Architect at
www.mrgsoft.com. There's a 15 day trial and you may get all the info you
need trying different things out within the trial period and looking at the
generated System.Drawing code.
 
* "ray well said:
in order to place a string of text at a specific place on a printed page, i
need to know its width in pixels at a certain font size. in vb6 there used
to be a function something like 'TextWidth' to which you would feed a string
and get its width.

Have a look at the 'Graphics.MeasureString' method.
 
Back
Top