DataGridViewCell.GetPreferredSize 方法

定义

计算单元格的首选大小(以像素为单位)。

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
Protected Overridable Function GetPreferredSize (graphics As Graphics, cellStyle As DataGridViewCellStyle, rowIndex As Integer, constraintSize As Size) As Size

参数

graphics
Graphics

用于绘制单元格的 Graphics

cellStyle
DataGridViewCellStyle

一个 DataGridViewCellStyle,它表示单元格样式。

rowIndex
Int32

单元格的从零开始的行索引。

constraintSize
Size

单元格允许的最大大小。

返回

一个 Size,它表示单元格的首选大小(以像素为单位)。

注解

GetPreferredSize基类DataGridViewCell中的 方法始终返回Size宽度和高度为 -1 的 。 但是,此方法在派生单元格类中被重写,以返回正确的值。

适用于

另请参阅