DataGridColumnStyle.GetPreferredSize(Graphics, Object) メソッド

定義

派生クラスでオーバーライドされると、指定した値の幅および高さを取得します。 この幅と高さは、ユーザーが DataGridTableStyle を使用して 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 オブジェクト。

value
Object

画面の高さおよび幅を確認するオブジェクト値。

戻り値

セルの大きさを格納する Size

次のコード例では、 メソッドを GetPreferredSize 使用して値の最適なサイズを返します。

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 します。

適用対象

こちらもご覧ください