DataGridViewCell.MeasureTextHeight Method

Definition

Gets the height, in pixels, of the specified text.

Overloads

MeasureTextHeight(Graphics, String, Font, Int32, TextFormatFlags, Boolean)

Gets the height, in pixels, of the specified text, given the specified characteristics. Also indicates whether the required width is greater than the specified maximum width.

MeasureTextHeight(Graphics, String, Font, Int32, TextFormatFlags)

Gets the height, in pixels, of the specified text, given the specified characteristics.

MeasureTextHeight(Graphics, String, Font, Int32, TextFormatFlags, Boolean)

Source:
DataGridViewCell.cs
Source:
DataGridViewCell.cs
Source:
DataGridViewCell.cs

Gets the height, in pixels, of the specified text, given the specified characteristics. Also indicates whether the required width is greater than the specified maximum width.

C#
public static int MeasureTextHeight(System.Drawing.Graphics graphics, string text, System.Drawing.Font font, int maxWidth, System.Windows.Forms.TextFormatFlags flags, out bool widthTruncated);
C#
public static int MeasureTextHeight(System.Drawing.Graphics graphics, string? text, System.Drawing.Font font, int maxWidth, System.Windows.Forms.TextFormatFlags flags, out bool widthTruncated);

Parameters

graphics
Graphics

The Graphics used to render the text.

text
String

The text to measure.

font
Font

The Font applied to the text.

maxWidth
Int32

The maximum width of the text.

flags
TextFormatFlags

A bitwise combination of TextFormatFlags values to apply to the text.

widthTruncated
Boolean

Set to true if the required width of the text is greater than maxWidth.

Returns

The height, in pixels, of the text.

Exceptions

graphics is null.

-or-

font is null.

maxWidth is less than 1.

flags is not a valid bitwise combination of TextFormatFlags values.

Remarks

If multiple lines are required and the specified formatting allows it, the height returned is the combined height of all lines.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

MeasureTextHeight(Graphics, String, Font, Int32, TextFormatFlags)

Source:
DataGridViewCell.cs
Source:
DataGridViewCell.cs
Source:
DataGridViewCell.cs

Gets the height, in pixels, of the specified text, given the specified characteristics.

C#
public static int MeasureTextHeight(System.Drawing.Graphics graphics, string text, System.Drawing.Font font, int maxWidth, System.Windows.Forms.TextFormatFlags flags);
C#
public static int MeasureTextHeight(System.Drawing.Graphics graphics, string? text, System.Drawing.Font font, int maxWidth, System.Windows.Forms.TextFormatFlags flags);

Parameters

graphics
Graphics

The Graphics used to render the text.

text
String

The text to measure.

font
Font

The Font applied to the text.

maxWidth
Int32

The maximum width of the text.

flags
TextFormatFlags

A bitwise combination of TextFormatFlags values to apply to the text.

Returns

The height, in pixels, of the text.

Exceptions

graphics is null.

-or-

font is null.

maxWidth is less than 1.

flags is not a valid bitwise combination of TextFormatFlags values.

Remarks

If multiple lines are required and the specified formatting allows it, the height returned is the combined height of all lines.

See also

Applies to

.NET Framework 4.8.1 and other versions
Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9