Measures the specified string when drawn with the specified System.Drawing.Font and formatted with the specified System.Drawing.StringFormat.
- text
- String to measure.
- font
- System.Drawing.Font defines the text format of the string.
- origin
- System.Drawing.PointF structure that represents the upper-left corner of the string.
- stringFormat
- System.Drawing.StringFormat that represents formatting information, such as line spacing, for the string.
This method returns a System.Drawing.SizeF structure that represents the size, in the units specified by the Graphics.PageUnit property, of the string specified by the text parameter as drawn with the font parameter and the stringFormat parameter.
The erload:System.Drawing.Graphics.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 erload:System.Drawing.Graphics.DrawString method adjusts glyph points to optimize display quality and might display a string narrower than reported by erload:System.Drawing.Graphics.MeasureString. To obtain metrics suitable for adjacent strings in layout (for example, when implementing formatted text), use the Graphics.MeasureCharacterRanges(string, Font, RectangleF, StringFormat) method or one of the Graphics.MeasureString(string, Font, PointF, StringFormat) methods that takes a System.Drawing.StringFormat, and pass StringFormat.GenericTypographic. Also, ensure the Graphics.TextRenderingHint for the System.Drawing.Graphics is System.Drawing.Text.TextRenderingHint.AntiAlias.