DataGridTextBoxColumn::GetPreferredSize Method (Graphics^, Object^)
.NET Framework (current version)
Returns the optimum width and height of the cell in a specified row relative to the specified value.
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Parameters
- g
-
Type:
System.Drawing::Graphics^
A Graphics object used to draw shapes on the screen.
- value
-
Type:
System::Object^
The value to draw.
The optimum width and height is calculated by measuring the string size, taking into account its font and attributes, and adding margin values.
The following example uses GetPreferredSize to return a Size.
public ref class MyGridColumn: public DataGridTextBoxColumn { public: Size GetPrefSize( Graphics^ g, String^ val ) { return this->GetPreferredSize( g, val ); } }; public ref class Form1: public Form { protected: DataGrid^ dataGrid1; private: void GetPreferredSize() { Graphics^ g; g = this->CreateGraphics(); System::Drawing::Size gridPreferredSize; 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"; gridPreferredSize = myTextColumn->GetPrefSize( g, myVal ); Console::WriteLine( gridPreferredSize ); } };
.NET Framework
Available since 1.1
Available since 1.1
Show: