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

정의

파생 클래스에서 재정의된 경우 지정한 값의 너비와 높이를 가져옵니다.When overridden in a derived class, gets the width and height of the specified value. 너비와 높이는 DataGridTableStyle을 사용하여 DataGridColumnStyle로 이동할 때 사용됩니다.The width and height are used when the user navigates to DataGridTableStyle using the DataGridColumnStyle.

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

매개 변수

g
Graphics Graphics Graphics Graphics

Graphics 개체입니다.A Graphics object.

value
Object Object Object Object

화면 높이와 너비를 알고자 하는 개체 값입니다.An object value for which you want to know the screen height and width.

반환

셀 크기를 포함하는 Size입니다.A Size that contains the dimensions of the cell.

예제

다음 코드 예제에서는 GetPreferredSize 값에 대 한 최적의 크기를 반환 하는 방법입니다.The following code example uses the GetPreferredSize method to return the optimum size for a value.

public ref class MyGridColumn: public DataGridTextBoxColumn
{
public:
   Size GetPrefSize( Graphics^ g, String^ thisString )
   {
      return this->GetPreferredSize( 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();
      System::Drawing::Size s = myGridColumn->GetPrefSize( 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();
    Size s =myGridColumn.GetPrefSize(g, "A string");
 }
}

public class MyGridColumn:DataGridTextBoxColumn{
   public Size GetPrefSize(Graphics g, string thisString){
      return this.GetPreferredSize(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()
      Dim s As Size = myGridColumn.GetPrefSize(g, "A string")
   End Sub 

End Class 

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

설명

사용 하 여 GetPreferredSize 너비를 결정 하는 열 크기를 조정 해야에 특정 문자열이 나 숫자가 지정 된 합니다.Use GetPreferredSize to determine the width a column should resize to, given a particular string or numeral.

적용 대상

추가 정보