Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All
Expand Minimize

DataGridViewCell.MeasureTextPreferredSize Method

Note: This method is new in the .NET Framework version 2.0.

Gets the ideal height and width of the specified text given the specified characteristics.

Namespace: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public static Size MeasureTextPreferredSize (
	Graphics graphics,
	string text,
	Font font,
	float maxRatio,
	TextFormatFlags flags
)
public static Size MeasureTextPreferredSize (
	Graphics graphics, 
	String text, 
	Font font, 
	float maxRatio, 
	TextFormatFlags flags
)
public static function MeasureTextPreferredSize (
	graphics : Graphics, 
	text : String, 
	font : Font, 
	maxRatio : float, 
	flags : TextFormatFlags
) : Size

Parameters

graphics

The Graphics used to render the text.

text

The text to measure.

font

The Font applied to the text.

maxRatio

The maximum width-to-height ratio of the block of text.

flags

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

Return Value

A Size representing the preferred height and width of the text.

Exception typeCondition

ArgumentNullException

graphics is a null reference (Nothing in Visual Basic).

-or-

font is a null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

maxRatio is less than or equal to 0.

InvalidEnumArgumentException

flags is not a valid bitwise combination of TextFormatFlags values.

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

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2015 Microsoft