When overridden in a derived class, gets the optimum width and height of the specified value.
[Visual Basic] MustOverride Public Function GetPreferredSize( _ ByVal g As Graphics, _ ByVal value As Object _ ) As Size [C#] public abstract Size GetPreferredSize( Graphics g, object value ); [C++] public: virtual Size GetPreferredSize( Graphics* g, Object* value ) = 0; [JScript] public abstract function GetPreferredSize( g : Graphics, value : Object ) : Size;
A Size that contains the dimensions of the cell.
Use GetPreferredSize to determine the width a column should resize to, given a particular string or numeral.
The following example shows a possible override of the GetPreferredSize method.
[Visual Basic]
Overrides Function GetNaturalExtents(ByVal g As UI.System.Drawing.Graphics, _ ByVal value As object) As UI.System.Drawing.Size Dim mySize As System.Drawing.Size ' Use the MeasureString method to determine the size. Dim layoutArea As System.Drawing.SizeF Dim stringFormat As System.Drawing.Advanced.StringFormat Dim charFitted As Long Dim linesFilled As Long ' Not shown: calculate layoutArea, stringFormat, charFitted, and linesFilled Set mySize = MeasureString(value, Me.Font, layoutArea, stringFormat, charFitted, linesFitted) Set GetNaturalExtents = mySize End Function
DataGridColumn Class | DataGridColumn Members | System.WinForms Namespace | GetPreferredHeight | GetMinimumHeight