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
text
drawn 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
text
stringThe text to measure.
font
FontThe Font to apply to the measured text.
proposedSize
SizeDThe 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
dc
GraphicsThe device context in which to measure the text.
text
stringThe text to measure.
font
FontThe Font to apply to the measured text.
Returns
- SizeD
The SizeD, in pixels, of
text
drawn in a single line with the specifiedfont
in 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
dc
GraphicsThe device context in which to measure the text.
text
stringThe text to measure.
font
FontThe Font to apply to the measured text.
proposedSize
SizeDThe 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
text
stringThe text to measure.
font
FontThe Font to apply to the measured text.
proposedSize
SizeDThe SizeD of the initial bounding rectangle.
flags
TextFormatFlagsThe 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
dc
GraphicsThe device context in which to measure the text.
text
stringThe text to measure.
font
FontThe Font to apply to the measured text.
proposedSize
SizeDThe SizeD of the initial bounding rectangle.
flags
TextFormatFlagsThe formatting instructions to apply to the measured text.