This documentation is archived and is not being maintained.

DataGridViewCell.MeasureTextSize Method

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

Gets the 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 MeasureTextSize (
	Graphics graphics,
	string text,
	Font font,
	TextFormatFlags flags
)
public static Size MeasureTextSize (
	Graphics graphics, 
	String text, 
	Font font, 
	TextFormatFlags flags
)
public static function MeasureTextSize (
	graphics : Graphics, 
	text : String, 
	font : Font, 
	flags : TextFormatFlags
) : Size

Parameters

graphics

The Graphics used to render the text.

text

The text to measure.

font

The Font applied to the text.

flags

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

Return Value

A Size representing the 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).

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
Show: