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. PreferredSizeSize如果单元格未包含在表中,则返回的宽度和高度均为-1。PreferredSize returns a Size with a width and height of -1 if the cell is not contained in a table.

如果该单元格位于 DataGridViewColumnResizable 属性设置为的中,则将 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.

适用于

另请参阅