DataGridColumnStyle.GetPreferredHeight(Graphics, Object) 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
在派生类中被重写时,将获取自动调整列的大小所用的高度。
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
参数
- value
- Object
一个对象值,该值是需要知道屏幕高度和宽度的值。
返回
自动调整单元格大小时所用高度。
示例
下面的代码示例使用 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 以重设长字符串列的高度大小。