DataGridTextBoxColumn.GetPreferredSize(Graphics, Object) DataGridTextBoxColumn.GetPreferredSize(Graphics, Object) DataGridTextBoxColumn.GetPreferredSize(Graphics, Object) DataGridTextBoxColumn.GetPreferredSize(Graphics, Object) Method

Definition

Gibt die optimale Breite und Höhe einer Zelle in einer angegebenen Zeile relativ zum angegebenen Wert zurück.Returns the optimum width and height of the cell in a specified row relative to the specified value.

protected public:
 override System::Drawing::Size GetPreferredSize(System::Drawing::Graphics ^ g, System::Object ^ value);
protected internal override System.Drawing.Size GetPreferredSize (System.Drawing.Graphics g, object value);
override this.GetPreferredSize : System.Drawing.Graphics * obj -> System.Drawing.Size
Protected Friend Overrides Function GetPreferredSize (g As Graphics, value As Object) As Size

Parameter

g
Graphics Graphics Graphics Graphics

Ein Graphics-Objekt zum Zeichnen von Formen auf dem Bildschirm.A Graphics object used to draw shapes on the screen.

value
Object Object Object Object

Der zu zeichnende Wert.The value to draw.

Gibt zurück

Eine Size, die die Abmessungen der Zelle enthält.A Size that contains the dimensions of the cell.

Beispiele

Im folgenden Beispiel wird GetPreferredSize verwendet, um Sizezurückzugeben.The following example uses GetPreferredSize to return a Size.

public ref class MyGridColumn: public DataGridTextBoxColumn
{
public:
   Size GetPrefSize( Graphics^ g, String^ val )
   {
      return this->GetPreferredSize( g, val );
   }

};

public ref class Form1: public Form
{
protected:
   DataGrid^ dataGrid1;

private:
   void GetPreferredSize()
   {
      Graphics^ g;
      g = this->CreateGraphics();
      System::Drawing::Size gridPreferredSize;
      MyGridColumn^ myTextColumn;
      
      // Assuming column 1 of a DataGrid control is a 
      // DataGridTextBoxColumn.
      myTextColumn = dynamic_cast<MyGridColumn^>(dataGrid1->TableStyles[ 0 ]->GridColumnStyles[ 1 ]);
      String^ myVal;
      myVal = "A long string value";
      gridPreferredSize = myTextColumn->GetPrefSize( g, myVal );
      Console::WriteLine( gridPreferredSize );
   }

};
public class Form1: Form
{
 protected DataGrid dataGrid1;

private void GetPreferredSize(){
   Graphics g;
   g = this.CreateGraphics();
   Size gridPreferredSize;
   MyGridColumn myTextColumn;
    // Assuming column 1 of a DataGrid control is a 
    // DataGridTextBoxColumn.
   myTextColumn = (MyGridColumn)
   dataGrid1.TableStyles[0].GridColumnStyles[1];
   string myVal;
   myVal = "A long string value";
   gridPreferredSize = myTextColumn.GetPrefSize(g, myVal);
   Console.WriteLine(gridPreferredSize);
   }
}

public class MyGridColumn:DataGridTextBoxColumn{
   public Size GetPrefSize(Graphics g, string val){
      return this.GetPreferredSize(g, val);
   }
}
Public Class Form1
    Inherits Form
    Protected dataGrid1 As DataGrid
    
    Private Sub GetPreferredSize()
        Dim g As Graphics
        g = Me.CreateGraphics()
        Dim gridPreferredSize As Size
        Dim myTextColumn As MyGridColumn
        ' Assuming column 1 of a DataGrid control is a 
        ' DataGridTextBoxColumn.
        myTextColumn = CType(dataGrid1.TableStyles(0). _
        GridColumnStyles(1), MyGridColumn)
        Dim myVal As String
        myVal = "A long string value"
        gridPreferredSize = myTextColumn.GetPrefSize _
        (g, myVal)
        Console.WriteLine(gridPreferredSize)
    End Sub 
End Class 

Public Class MyGridColumn
Inherits DataGridTextBoxColumn
   public Function GetPrefSize(g As Graphics , val As string) _
   As Size
      return me.GetPreferredSize(g, val)
   End Function
End Class

Hinweise

Die optimale Breite und Höhe wird berechnet, indem die Zeichen folgen Größe gemessen wird, wobei die Schriftart und Attribute berücksichtigt werden und Rand Werte hinzugefügt werden.The optimum width and height is calculated by measuring the string size, taking into account its font and attributes, and adding margin values.

Gilt für:

Siehe auch