Determining length of a string in pixels

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I am drawing text on a screen using graphicsObject.DrawString().

Prior to doing this I need to determine the length in pixels that the string
will be when it is rendered. I know I've read this before but can not find
it now that I need it.

Also - is there a simple way to center the text within a rectangel?

And - Thanks for your responses I really appreciate it!
 
Hi,

HaySeed said:
I am drawing text on a screen using graphicsObject.DrawString().

Prior to doing this I need to determine the length in pixels that the
string
will be when it is rendered. I know I've read this before but can not
find
it now that I need it.

Check out the 'Graphics' object's 'MeasureString' method.
Also - is there a simple way to center the text within a rectangel?

There is an overloaded version of 'DrawString' which has parameters
'layoutRectangle' and 'format'. You can specify the alignment in the
'StringFormat' passed to the 'format' parameter.
 
Back
Top