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;
A Size that contains the dimensions of the cell.
The optimum width and height is calculated by measuring the string size, taking into account its font and attributes, and adding margin values.
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
DataGridTextBoxColumn Class | DataGridTextBoxColumn Members | System.WinForms Namespace | GetPreferredHeight | GetMinimumHeight | Graphics | Size