DataGridViewCell.PreferredSize 屬性

定義

取得能夠容納儲存格的矩形區域大小 (以像素為單位)。Gets the size, in pixels, of a rectangular area into which the cell can fit.

public:
 property System::Drawing::Size PreferredSize { System::Drawing::Size get(); };
[System.ComponentModel.Browsable(false)]
public System.Drawing.Size PreferredSize { get; }
[<System.ComponentModel.Browsable(false)>]
member this.PreferredSize : System.Drawing.Size
Public ReadOnly Property PreferredSize As Size

屬性值

Size

Size,包含高度和寬度 (單位為像素)。A Size containing the height and width, in pixels.

屬性

例外狀況

ColumnIndex 小於 0,表示儲存格是資料列行首儲存格。ColumnIndex is less than 0, indicating that the cell is a row header cell.

包含儲存格的資料列是共用的資料列。The row containing the cell is a shared row.

-或--or-

儲存格是資料行行首儲存格。The cell is a column header cell.

備註

屬性會傳回資料格擁有的資料 PreferredSize 列和資料行所計算之資料格的自然大小。The PreferredSize property returns the natural size of the cell computed by the cell's owning row and column. PreferredSize 如果資料 Size 格不包含在資料表中,則會傳回寬度和高度為-1 的。PreferredSize returns a Size with a width and height of -1 if the cell is not contained in a table.

如果儲存格位於 DataGridViewColumn ,其 Resizable 屬性設定為 false ,則會針對寬度傳回-1。If the cell is in a DataGridViewColumn that has its Resizable property set to false, -1 is returned for the width.

這個方法會依賴 GetFormattedValue 方法。This method relies on the GetFormattedValue method.

適用於

另請參閱