DataGridViewCell.PreferredSize DataGridViewCell.PreferredSize DataGridViewCell.PreferredSize DataGridViewCell.PreferredSize Property

定义

获取适合该单元格的矩形区域的大小(以像素为单位)。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; }
member this.PreferredSize : System.Drawing.Size
Public ReadOnly Property PreferredSize As 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.

适用于

另请参阅