Getting string width

vendiddy

Well-known member
Joined
May 14, 2006
Messages
64
Programming Experience
1-3
Hi, I would like to get the width of a string.

Given x & y coordinates I would like to draw a string centered at x, y. I would also like to create a rectangle that surrounds this string.

The problem is that I would like to calculate the widths and coordinates of all of the shapes outside of the paint event and the MeasureString method only seems to work inside the paint event.

Thanks!
 
Create a graphics object from the context you want to draw with the CreateGraphics method of the control. This is the purpose of the CreateGraphics method, to enable such measure 'outside' the Paint event. Remember to Dispose.
 
Back
Top