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!

Re: Determining length of a string in pixels by Herfried

Herfried
Thu Dec 08 16:49:00 CST 2005

Hi,

"HaySeed" <HaySeed@discussions.microsoft.com> schrieb:
>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.

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>