DataGridColumnStyle.GetPreferredHeight(Graphics, Object) Méthode

Définition

En cas de substitution dans une classe dérivée, obtient la hauteur utilisée pour redimensionner automatiquement les colonnes.

protected public:
 abstract int GetPreferredHeight(System::Drawing::Graphics ^ g, System::Object ^ value);
protected internal abstract int GetPreferredHeight (System.Drawing.Graphics g, object value);
abstract member GetPreferredHeight : System.Drawing.Graphics * obj -> int
Protected Friend MustOverride Function GetPreferredHeight (g As Graphics, value As Object) As Integer

Paramètres

g
Graphics

Objet Graphics.

value
Object

Valeur d'objet pour lequel vous souhaitez connaître la hauteur et la largeur à l'écran.

Retours

Int32

Hauteur utilisée pour redimensionner automatiquement une cellule.

Exemples

L’exemple de code suivant utilise la GetPreferredHeight méthode pour retourner la hauteur d’une cellule.

public ref class MyGridColumn: public DataGridTextBoxColumn
{
public:
   int GetPrefHeight( Graphics^ g, String^ thisString )
   {
      return this->GetPreferredHeight( g, thisString );
   }

};

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

private:
   void GetHeight()
   {
      MyGridColumn^ myGridColumn;
      
      // Get a DataGridColumnStyle of a DataGrid control.
      myGridColumn = dynamic_cast<MyGridColumn^>(dataGrid1->TableStyles[ 0 ]->GridColumnStyles[ "CompanyName" ]);
      
      // Create a Graphics object.
      Graphics^ g = this->CreateGraphics();
      Console::WriteLine( myGridColumn->GetPrefHeight( g, "A string" ) );
   }

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

private void GetHeight(){
    MyGridColumn myGridColumn;
    // Get a DataGridColumnStyle of a DataGrid control.
    myGridColumn = (MyGridColumn) dataGrid1.TableStyles[0].
    GridColumnStyles["CompanyName"];
    // Create a Graphics object.
    Graphics g = this.CreateGraphics();
    Console.WriteLine(myGridColumn.GetPrefHeight(g, "A string"));
 }
}

public class MyGridColumn:DataGridTextBoxColumn{
   public int GetPrefHeight(Graphics g, string thisString){
      return this.GetPreferredHeight(g,thisString);
   }
}
Public Class Form1
    Inherits Form
    Protected dataGrid1 As DataGrid
    

    Private Sub GetHeight()
        Dim myGridColumn As MyGridColumn
        ' Get a DataGridColumnStyle of a DataGrid control.
        myGridColumn = CType(dataGrid1.TableStyles(0). _
        GridColumnStyles("CompanyName"), myGridColumn)
        ' Create a Graphics object.
        Dim g As Graphics = Me.CreateGraphics()
        Console.WriteLine(myGridColumn.GetPrefHeight(g, "A string"))
    End Sub 

End Class 

Public Class MyGridColumn
Inherits DataGridTextBoxColumn
   public Function GetPrefHeight (g As Graphics , _
   thisString As String ) As Integer
      return me.GetPreferredHeight(g,thisString)
   End Function
End Class

Remarques

La GetPreferredSize valeur est généralement appelée à partir d’un événement de bas de souris pour redimensionner la hauteur d’une colonne pour une longue chaîne.

S’applique à

Voir aussi