NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

DataGridColumn.GetPreferredSize

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;

Parameters

g
A Graphics object.
value
A object value for which you want to know the screen height and width.

Return Value

A Size that contains the dimensions of the cell.

Remarks

Use GetPreferredSize to determine the width a column should resize to, given a particular string or numeral.

Example [Visual Basic]

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

See Also

DataGridColumn Class | DataGridColumn Members | System.WinForms Namespace | GetPreferredHeight | GetMinimumHeight