DataGridTextBoxColumn.GetPreferredHeight(Graphics, Object) Method
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
Gets the height to be used in for automatically resizing columns.
protected public:
override int GetPreferredHeight(System::Drawing::Graphics ^ g, System::Object ^ value);
protected internal override int GetPreferredHeight (System.Drawing.Graphics g, object value);
override this.GetPreferredHeight : System.Drawing.Graphics * obj -> int
Protected Friend Overrides Function GetPreferredHeight (g As Graphics, value As Object) As Integer
Parameters
- value
- Object
The value to draw.
Returns
The height the cells automatically resize to.
Examples
The following example uses the GetPreferredHeight to return the height a column is automatically resized to.
public ref class MyGridColumn: public DataGridTextBoxColumn
{
public:
int GetPrefHeight( Graphics^ g, String^ val )
{
return this->GetPreferredHeight( g, val );
}
};
public ref class Form1: public Form
{
protected:
DataGrid^ dataGrid1;
private:
void GetPreferredHeight()
{
Graphics^ g;
g = this->CreateGraphics();
int gridPreferredHeight;
MyGridColumn^ myTextColumn;
// Assuming column 1 of a DataGrid control is a
// DataGridTextBoxColumn.
myTextColumn = dynamic_cast<MyGridColumn^>(dataGrid1->TableStyles[ 0 ]->GridColumnStyles[ 1 ]);
String^ myVal;
myVal = "A long string value";
gridPreferredHeight = myTextColumn->GetPrefHeight( g, myVal );
Console::WriteLine( gridPreferredHeight );
}
};
public class Form1: Form
{
protected DataGrid dataGrid1;
private void GetPreferredHeight(){
Graphics g;
g = this.CreateGraphics();
int gridPreferredHeight;
MyGridColumn myTextColumn;
// Assuming column 1 of a DataGrid control is a
// DataGridTextBoxColumn.
myTextColumn = (MyGridColumn)
dataGrid1.TableStyles[0].GridColumnStyles[1];
string myVal;
myVal = "A long string value";
gridPreferredHeight= myTextColumn.GetPrefHeight(g, myVal);
Console.WriteLine(gridPreferredHeight);
}
}
public class MyGridColumn:DataGridTextBoxColumn{
public int GetPrefHeight(Graphics g, string val){
return this.GetPreferredHeight(g, val);
}
}
Public Class Form1
Inherits Form
Protected dataGrid1 As DataGrid
Private Sub GetPreferredHeight()
Dim g As Graphics
g = Me.CreateGraphics()
Dim gridPreferredHeight As Integer
Dim myTextColumn As MyGridColumn
' Assuming column 1 of a DataGrid control is a
' DataGridTextBoxColumn.
myTextColumn = CType(dataGrid1.TableStyles(0). _
GridColumnStyles(1), MyGridColumn)
Dim myVal As String
myVal = "A long string value"
gridPreferredHeight = myTextColumn.GetPrefHeight _
(g, myVal)
Console.WriteLine(gridPreferredHeight)
End Sub
End Class
Public Class MyGridColumn
Inherits DataGridTextBoxColumn
public Function GetPrefHeight(g As Graphics , val As string) _
As Integer
return me.GetPreferredHeight(g, val)
End Function
End Class
Applies to
See also
GitHub에서 Microsoft와 공동 작업
이 콘텐츠의 원본은 GitHub에서 찾을 수 있으며, 여기서 문제와 끌어오기 요청을 만들고 검토할 수도 있습니다. 자세한 내용은 참여자 가이드를 참조하세요.
.NET