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

定義

計算儲存格的慣用大小 (以像素為單位)。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 Graphics Graphics

繪製儲存格所用的 GraphicsThe Graphics used to draw the cell.

cellStyle
DataGridViewCellStyle DataGridViewCellStyle DataGridViewCellStyle

DataGridViewCellStyle ,表示儲存格的樣式。A DataGridViewCellStyle that represents the style of the cell.

rowIndex
Int32 Int32 Int32

儲存格之以零起始的資料列索引。The zero-based row index of the cell.

constraintSize
Size Size Size

儲存格可允許大小的最大值。The cell's maximum allowable size.

傳回

Size,表示儲存格的慣用大小 (以像素為單位)。A Size that represents the preferred size, in pixels, of the cell.

備註

基類中的GetPreferredSize方法Size一律會傳回,其寬度和高度為-1。 DataGridViewCellThe 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.

適用於

另請參閱