Method MeasureText
MeasureText(string, Font)
Provides the size, in pixels, of the specified text when drawn with the specified font.
public static SizeD MeasureText(string text, Font font)
Parameters
Returns
- SizeD
The SizeD, in pixels, of
textdrawn on a single line with the specifiedfont. You can manipulate how the text is drawn by using one of the DrawText(Graphics, string, Font, RectD, Color, TextFormatFlags) overloads that takes a TextFormatFlags parameter. For example, the default behavior of the TextRenderer is to add padding to the bounding rectangle of the drawn text to accommodate overhanging glyphs. If you need to draw a line of text without these extra spaces you should use the versions of DrawText(Graphics, string, Font, PointD, Color) and MeasureText(Graphics, string, Font) that take a SizeD and TextFormatFlags parameter. For an example, see MeasureText(Graphics, string, Font, SizeD, TextFormatFlags).
MeasureText(string, Font, SizeD)
Provides the size, in pixels, of the specified text when drawn with the specified font, using the specified size to create an initial bounding rectangle.
public static SizeD MeasureText(string text, Font font, SizeD proposedSize)
Parameters
textstringThe text to measure.
fontFontThe Font to apply to the measured text.
proposedSizeSizeDThe SizeD of the initial bounding rectangle.
Returns
MeasureText(Graphics, string, Font)
Provides the size, in pixels, of the specified text drawn with the specified font in the specified device context.
public static SizeD MeasureText(Graphics dc, string text, Font font)
Parameters
dcGraphicsThe device context in which to measure the text.
textstringThe text to measure.
fontFontThe Font to apply to the measured text.
Returns
- SizeD
The SizeD, in pixels, of
textdrawn in a single line with the specifiedfontin the specified device context.
MeasureText(Graphics, string, Font, SizeD)
Provides the size, in pixels, of the specified text when drawn with the specified font in the specified device context, using the specified size to create an initial bounding rectangle for the text.
public static SizeD MeasureText(Graphics dc, string text, Font font, SizeD proposedSize)
Parameters
dcGraphicsThe device context in which to measure the text.
textstringThe text to measure.
fontFontThe Font to apply to the measured text.
proposedSizeSizeDThe SizeD of the initial bounding rectangle.
Returns
MeasureText(string, Font, SizeD, TextFormatFlags)
Provides the size, in pixels, of the specified text when drawn with the specified font and formatting instructions, using the specified size to create the initial bounding rectangle for the text.
public static SizeD MeasureText(string text, Font font, SizeD proposedSize, TextFormatFlags flags)
Parameters
textstringThe text to measure.
fontFontThe Font to apply to the measured text.
proposedSizeSizeDThe SizeD of the initial bounding rectangle.
flagsTextFormatFlagsThe formatting instructions to apply to the measured text.
Returns
MeasureText(Graphics, string, Font, SizeD, TextFormatFlags)
Provides the size, in pixels, of the specified text when drawn with the specified device context, font, and formatting instructions, using the specified size to create the initial bounding rectangle for the text.
public static SizeD MeasureText(Graphics dc, string text, Font font, SizeD proposedSize, TextFormatFlags flags)
Parameters
dcGraphicsThe device context in which to measure the text.
textstringThe text to measure.
fontFontThe Font to apply to the measured text.
proposedSizeSizeDThe SizeD of the initial bounding rectangle.
flagsTextFormatFlagsThe formatting instructions to apply to the measured text.