DataGridViewCell.GetPreferredSize(Graphics, DataGridViewCellStyle, Int32, Size) 方法

定义

计算单元格的首选大小(以像素为单位)。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

参数

graphics
Graphics

用于绘制单元格的 GraphicsThe Graphics used to draw the cell.

cellStyle
DataGridViewCellStyle

一个 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.

返回

一个 Size,它表示单元格的首选大小(以像素为单位)。A Size that represents the preferred size, in pixels, of the cell.

注解

基类中的 GetPreferredSize 方法 DataGridViewCell 总是返回宽度和高度均为1的 SizeThe 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.

适用于

另请参阅