Graphics.MeasureString

MeasureString(string, Font)

Measures the specified string when drawn with the specified Font.

public SizeF MeasureString(string text, Font font)
ParameterTypeDescription
textStringString to measure.
fontFontFont that defines the text format of the string.

Return Value

This method returns a SizeF structure that represents the size, in the units specified by the PageUnit property, of the string specified by the text parameter as drawn with the font parameter.

See Also


MeasureString(string, Font, SizeF)

Measures the specified string when drawn with the specified Font.

public SizeF MeasureString(string text, Font font, SizeF layoutArea)
ParameterTypeDescription
textStringString to measure.
fontFontFont that defines the text format of the string.
layoutAreaSizeFSizeF structure that specifies the maximum layout area for the text.

Return Value

This method returns a SizeF structure that represents the size, in the units specified by the PageUnit property, of the string specified by the text parameter as drawn with the font parameter.

See Also


MeasureString(string, Font, int)

Measures the specified string when drawn with the specified Font.

public SizeF MeasureString(string text, Font font, int width)
ParameterTypeDescription
textStringString to measure.
fontFontFont that defines the text format of the string.
widthInt32Maximum width of the string in pixels.

Return Value

This method returns a SizeF structure that represents the size, in the units specified by the PageUnit property, of the string specified by the text parameter as drawn with the font parameter.

See Also


MeasureString(string, Font, PointF, StringFormat)

Measures the specified string when drawn with the specified Font and formatted with the specified StringFormat.

public SizeF MeasureString(string text, Font font, PointF origin, StringFormat stringFormat)
ParameterTypeDescription
textStringString to measure.
fontFontFont defines the text format of the string.
originPointFPointF structure that represents the upper-left corner of the string.
stringFormatStringFormatStringFormat that represents formatting information, such as line spacing, for the string.

Return Value

This method returns a SizeF structure that represents the size, in the units specified by the PageUnit property, of the string specified by the text parameter as drawn with the font parameter and the stringFormat parameter.

See Also


MeasureString(string, Font, int, StringFormat)

Measures the specified string when drawn with the specified Font and formatted with the specified StringFormat.

public SizeF MeasureString(string text, Font font, int width, StringFormat format)
ParameterTypeDescription
textStringString to measure.
fontFontFont that defines the text format of the string.
widthInt32Maximum width of the string.
formatStringFormatStringFormat that represents formatting information, such as line spacing, for the string.

Return Value

This method returns a SizeF structure that represents the size, in the units specified by the PageUnit property, of the string specified in the text parameter as drawn with the font parameter and the format parameter.

See Also


MeasureString(string, Font, SizeF, StringFormat)

Measures the specified string when drawn with the specified Font and formatted with the specified StringFormat.

public SizeF MeasureString(string text, Font font, SizeF layoutArea, StringFormat stringFormat)
ParameterTypeDescription
textStringString to measure.
fontFontFont defines the text format of the string.
layoutAreaSizeFSizeF structure that specifies the maximum layout area for the text.
stringFormatStringFormatStringFormat that represents formatting information, such as line spacing, for the string.

Return Value

This method returns a SizeF structure that represents the size, in the units specified by the PageUnit property, of the string specified in the text parameter as drawn with the font parameter and the stringFormat parameter.

See Also


MeasureString(string, Font, SizeF, StringFormat, out int, out int)

Measures the specified string when drawn with the specified Font and formatted with the specified StringFormat.

public SizeF MeasureString(string text, Font font, SizeF layoutArea, StringFormat stringFormat, 
    out int charactersFitted, out int linesFilled)
ParameterTypeDescription
textStringString to measure.
fontFontFont defines the text format of the string.
layoutAreaSizeFSizeF structure that specifies the maximum layout area for the text.
stringFormatStringFormatStringFormat that represents formatting information, such as line spacing, for the string.
charactersFittedInt32&Number of characters in the string.
linesFilledInt32&Number of text lines in the string.

Return Value

This method returns a SizeF structure that represents the size, in the units specified by the PageUnit property, of the string specified in the text parameter as drawn with the font parameter and the stringFormat parameter.

See Also