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!

DataGridTextBoxColumn.GetPreferredSize

Returns the optimum width and height of the cell in a specified row relative to the specified value.

[Visual Basic]
Overrides Public Function GetPreferredSize( _
   ByVal g As Graphics, _
   ByVal value As Object _
) As Size
[C#]
public override Size GetPreferredSize(
   Graphics g,
   object value
);
[C++]
public: override Size GetPreferredSize(
   Graphics* g,
   Object* value
);
[JScript]
public override function GetPreferredSize(
   g : Graphics,
   value : Object
) : Size;

Parameters

g
A Graphics object used to draw shapes on the screen.
value
The value to draw.

Return Value

A Size that contains the dimensions of the cell.

Remarks

The optimum width and height is calculated by measuring the string size, taking into account its font and attributes, and adding margin values.

Example [Visual Basic]

The following example uses GetPreferredSize to return a Size.

[Visual Basic]

Private Sub GetSize()
   Dim g As Graphics
   Set g = Me.CreateGraphics
   Dim mySize As System.Drawing.Size
   Dim dgeCol As DataGridTextBoxColumn
   ' Assuming column 1 of a DataGrid control is a DataGridTextBoxColumn.
   Set dgeCol = DataGrid1.GridColumns(1)
   ' Get the value contained by the cell using the CurrentCell.
   Dim myVal As Object
   myVal = dgeCol.DataGridTable.DataTable.Rows(DataGrid1.CurrentCell.RowNumber)

   Set s = dgeCol.GetNaturalExtents(g, myVal)
   Debug.Print s.Width, s.Height

End Sub

See Also

DataGridTextBoxColumn Class | DataGridTextBoxColumn Members | System.WinForms Namespace | GetPreferredHeight | GetMinimumHeight | Graphics | Size