System.Windows.Forms.TextRenderer.MeasureText Method

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.

Syntax

public static System.Drawing.Size MeasureText (System.Drawing.IDeviceContext dc, string text, System.Drawing.Font font, System.Drawing.Size proposedSize)

Parameters

dc
The device context in which to measure the text.
text
The text to measure.
font
The System.Drawing.Font to apply to the measured text.
proposedSize
The System.Drawing.Size of the initial bounding rectangle.

Returns

The System.Drawing.Size, in pixels, of text drawn with the specified font.

Remarks

The TextRenderer.MeasureText(System.Drawing.IDeviceContext, string, System.Drawing.Font, System.Drawing.Size) method uses the proposedSize parameter to indicate the relationship of height to width when determining the text size. When measuring text on a single line, if the proposedSize parameter represents a System.Drawing.Size with a height dimension greater than int.MaxValue, the returned System.Drawing.Size will be adjusted to reflect the actual height of the text.

Requirements

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Assembly Versions: 2.0.0.0
Since: .NET 2.0