DataGridColumnStyle.GetPreferredHeight(Graphics, Object) Método

Definição

Quando substituído em uma classe derivada, obtém a altura usada para redimensionar automaticamente as colunas.When overridden in a derived class, gets the height used for automatically resizing columns.

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

Parâmetros

g
Graphics

Um objeto Graphics.A Graphics object.

value
Object

Um valor de objeto para o qual você deseja saber a largura e altura da tela.An object value for which you want to know the screen height and width.

Retornos

A altura usada para redimensionar automaticamente uma célula.The height used for auto resizing a cell.

Exemplos

O exemplo de código a seguir GetPreferredHeight usa o método para retornar a altura de uma célula.The following code example uses the GetPreferredHeight method to return the height of a cell.

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

Comentários

O GetPreferredSize geralmente será invocado de um evento de mouse para baixo para redimensionar a altura de uma coluna para uma cadeia de caracteres longa.The GetPreferredSize will usually be invoked from a mouse down event to resize a column's height for a long string.

Aplica-se a

Veja também