DataGridColumnStyle.GetPreferredHeight(Graphics, Object) 메서드

정의

파생 클래스에서 재정의된 경우 열을 자동으로 크기 조정하는 데 사용된 높이를 가져옵니다.

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

매개 변수

g
Graphics

Graphics 개체입니다.

value
Object

화면 높이와 너비를 알고자 하는 개체 값입니다.

반환

Int32

셀을 자동으로 크기 조정하는 데 사용된 높이입니다.

예제

다음 코드 예제에서는 셀의 높이 반환 하는 메서드를 사용 합니다 GetPreferredHeight .

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

설명

GetPreferredSize 일반적으로 긴 문자열에 대한 열 높이의 크기를 조정하기 위해 마우스 아래쪽 이벤트에서 호출됩니다.

적용 대상

추가 정보