DataGridViewCell.PreferredSize 屬性

定義

取得能夠容納儲存格的矩形區域大小 (以像素為單位)。

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,包含高度和寬度 (單位為像素)。

屬性

例外狀況

ColumnIndex 小於 0,表示儲存格是資料列行首儲存格。

包含儲存格的資料列是共用的資料列。

-或-

儲存格是資料行行首儲存格。

備註

屬性 PreferredSize 會傳回儲存格擁有之資料列和資料行所計算之儲存格的自然大小。 PreferredSizeSize如果儲存格未包含在表格中,則會傳回寬度和高度為 -1 的 。

如果儲存格位於 的 中 DataGridViewColumn ,且其 Resizable 屬性設定為 false ,則會針對寬度傳回 -1。

這個方法依賴 GetFormattedValue 方法。

適用於

另請參閱