Graphics.MeasureString Method (String, Font, PointF, StringFormat)
Assembly: System.Drawing (in System.Drawing.dll)
member MeasureString : text:string * font:Font * origin:PointF * stringFormat:StringFormat -> SizeF
String to measure.
PointF structure that represents the upper-left corner of the string.
The MeasureString method is designed for use with individual strings and includes a small amount of extra space before and after the string to allow for overhanging glyphs. Also, the DrawString method adjusts glyph points to optimize display quality and might display a string narrower than reported by MeasureString. To obtain metrics suitable for adjacent strings in layout (for example, when implementing formatted text), use the MeasureCharacterRanges method or one of the methods that takes a StringFormat, and pass GenericTypographic. Also, ensure the TextRenderingHint for the Graphics is AntiAlias.
Creates a string to measure and a font object set to Arial (16 point)
Creates a point to locate the upper-left corner of the string.
Creates a string format object and sets its format flags to DirectionVertical.
Creates a size object to measure the string.
Measures the size of the string, using the string, the font object, the locating point, and the string format.
Draws a red rectangle using the locating point and the measured size of the string.
Draws the string within the drawn rectangle.
The result is a vertical rectangle enclosing a vertical string.
Available since 1.1