DataGridViewCell.GetPreferredSize(Graphics, DataGridViewCellStyle, Int32, Size) Method

Definition

Calculates the preferred size, in pixels, of the cell.

protected:
 virtual System::Drawing::Size GetPreferredSize(System::Drawing::Graphics ^ graphics, System::Windows::Forms::DataGridViewCellStyle ^ cellStyle, int rowIndex, System::Drawing::Size constraintSize);
protected virtual System.Drawing.Size GetPreferredSize (System.Drawing.Graphics graphics, System.Windows.Forms.DataGridViewCellStyle cellStyle, int rowIndex, System.Drawing.Size constraintSize);
abstract member GetPreferredSize : System.Drawing.Graphics * System.Windows.Forms.DataGridViewCellStyle * int * System.Drawing.Size -> System.Drawing.Size
override this.GetPreferredSize : System.Drawing.Graphics * System.Windows.Forms.DataGridViewCellStyle * int * System.Drawing.Size -> System.Drawing.Size

Parameters

graphics
Graphics

The Graphics used to draw the cell.

cellStyle
DataGridViewCellStyle

A DataGridViewCellStyle that represents the style of the cell.

rowIndex
Int32

The zero-based row index of the cell.

constraintSize
Size

The cell's maximum allowable size.

Returns

A Size that represents the preferred size, in pixels, of the cell.

Remarks

The GetPreferredSize method in the base class DataGridViewCell always returns a Size with a width and height of -1. However, this method is overridden in the derived cell classes to return proper values.

Applies to

See also