DataGridColumnStyle.GetPreferredHeight 方法
在派生类中被重写时,将获取自动调整列的大小所用的高度。
**命名空间:**System.Windows.Forms
**程序集:**System.Windows.Forms(在 system.windows.forms.dll 中)
语法
声明
Protected Friend MustOverride Function GetPreferredHeight ( _
g As Graphics, _
value As Object _
) As Integer
用法
Dim g As Graphics
Dim value As Object
Dim returnValue As Integer
returnValue = Me.GetPreferredHeight(g, value)
protected internal abstract int GetPreferredHeight (
Graphics g,
Object value
)
protected public:
virtual int GetPreferredHeight (
Graphics^ g,
Object^ value
) abstract
protected abstract int GetPreferredHeight (
Graphics g,
Object value
)
protected internal abstract function GetPreferredHeight (
g : Graphics,
value : Object
) : int
参数
- g
一个 Graphics 对象。
- value
一个对象值,该值是需要知道屏幕高度和宽度的值。
返回值
自动调整单元格大小时所用高度。
备注
通常从鼠标按下事件调用 GetPreferredSize 以针对长字符串来调整列的高度。
示例
下面的代码示例使用 GetPreferredHeight 方法来返回单元格的高度。
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
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 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 extends Form
{
protected DataGrid dataGrid1;
private void GetHeight()
{
MyGridColumn myGridColumn;
// Get a DataGridColumnStyle of a DataGrid control.
myGridColumn =
(MyGridColumn)(dataGrid1.get_TableStyles().
get_Item(0).get_GridColumnStyles().get_Item("CompanyName"));
// Create a Graphics object.
Graphics g = this.CreateGraphics();
Console.WriteLine(myGridColumn.GetPrefHeight(g, "A string"));
} //GetHeight
} //Form1
public class MyGridColumn extends DataGridTextBoxColumn
{
public int GetPrefHeight(Graphics g, String thisString)
{
return this.GetPreferredHeight(g, thisString);
} //GetPrefHeight
} //MyGridColumn
平台
Windows 98、Windows 2000 SP4、Windows CE、Windows Millennium Edition、Windows Mobile for Pocket PC、Windows Mobile for Smartphone、Windows Server 2003、Windows XP Media Center Edition、Windows XP Professional x64 Edition、Windows XP SP2、Windows XP Starter Edition
.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求。
版本信息
.NET Framework
受以下版本支持:2.0、1.1、1.0
请参见
参考
DataGridColumnStyle 类
DataGridColumnStyle 成员
System.Windows.Forms 命名空间
GetPreferredSize
GetMinimumHeight