Table of Contents

Method MeasureText

Namespace
Alternet.Drawing
Assembly
Alternet.UI.Common.dll

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

text string

The text to measure.

font Font

The Font to apply to the measured text.

Returns

SizeD

The SizeD, in pixels, of text drawn on a single line with the specified font. 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 string

The text to measure.

font Font

The Font to apply to the measured text.

proposedSize SizeD

The SizeD of the initial bounding rectangle.

Returns

SizeD

The SizeD, in pixels, of text drawn with the specified font.

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 Graphics

The device context in which to measure the text.

text string

The text to measure.

font Font

The Font to apply to the measured text.

Returns

SizeD

The SizeD, in pixels, of text drawn in a single line with the specified font 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 Graphics

The device context in which to measure the text.

text string

The text to measure.

font Font

The Font to apply to the measured text.

proposedSize SizeD

The SizeD of the initial bounding rectangle.

Returns

SizeD

The SizeD, in pixels, of text drawn with the specified font.

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 string

The text to measure.

font Font

The Font to apply to the measured text.

proposedSize SizeD

The SizeD of the initial bounding rectangle.

flags TextFormatFlags

The formatting instructions to apply to the measured text.

Returns

SizeD

The SizeD, in pixels, of text drawn with the specified font and format.

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 Graphics

The device context in which to measure the text.

text string

The text to measure.

font Font

The Font to apply to the measured text.

proposedSize SizeD

The SizeD of the initial bounding rectangle.

flags TextFormatFlags

The formatting instructions to apply to the measured text.

Returns

SizeD

The SizeD, in pixels, of text drawn with the specified font and format.