DataGridViewCellStyle.Padding 属性

定义

获取或设置 DataGridViewCell 的边缘和它的内容之间的距离。Gets or sets the space between the edge of a DataGridViewCell and its content.

public:
 property System::Windows::Forms::Padding Padding { System::Windows::Forms::Padding get(); void set(System::Windows::Forms::Padding value); };
public System.Windows.Forms.Padding Padding { get; set; }
member this.Padding : System.Windows.Forms.Padding with get, set
Public Property Padding As Padding

属性值

Padding,它表示 DataGridViewCell 的边缘和它的内容之间的距离。A Padding that represents the space between the edge of a DataGridViewCell and its content.

示例

下面的代码示例演示如何在包含所有者描述行的DataGridView控件中使用此属性。The following code example illustrates the use of this property in a DataGridView control that contains owner-drawn rows. 每行显示的文本横跨常规单元格内容下的行的整个宽度。Each row displays text that spans the entire width of the row underneath the regular cell content. Padding属性用于为此文本提供额外空间。The Padding property is used to provide the extra space for this text. 在此示例中, 所需的额外高度存储在一个名CUSTOM_CONTENT_HEIGHT为的常量中。In the example, the extra height required is stored in a constant called CUSTOM_CONTENT_HEIGHT.

此代码示例摘自一个更大的示例。This code example is part of a larger example. 有关完整的示例,请参阅如何:自定义 Windows 窗体 DataGridView 控件中的行的外观。For the complete example, see How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

// Set a cell padding to provide space for the top of the focus 
// rectangle and for the content that spans multiple columns. 
Padding newPadding = new Padding(0, 1, 0, CUSTOM_CONTENT_HEIGHT);
this.dataGridView1.RowTemplate.DefaultCellStyle.Padding = newPadding;

// Set the selection background color to transparent so 
// the cell won't paint over the custom selection background.
this.dataGridView1.RowTemplate.DefaultCellStyle.SelectionBackColor =
    Color.Transparent;

// Set the row height to accommodate the content that 
// spans multiple columns.
this.dataGridView1.RowTemplate.Height += CUSTOM_CONTENT_HEIGHT;
' Set a cell padding to provide space for the top of the focus 
' rectangle and for the content that spans multiple columns. 
Dim newPadding As New Padding(0, 1, 0, CUSTOM_CONTENT_HEIGHT)
Me.dataGridView1.RowTemplate.DefaultCellStyle.Padding = newPadding

' Set the selection background color to transparent so 
' the cell won't paint over the custom selection background.
Me.dataGridView1.RowTemplate.DefaultCellStyle.SelectionBackColor = _
    Color.Transparent

' Set the row height to accommodate the normal cell content and the 
' content that spans multiple columns.
Me.dataGridView1.RowTemplate.Height += CUSTOM_CONTENT_HEIGHT

注解

设置属性将影响的DataGridViewCell编辑控件的绘制位置。 PaddingSetting the Padding property affects where the editing control of the DataGridViewCell is drawn. 例如Padding , 如果将设置DataGridViewTextBoxCell为, 而将设置System.Windows.Forms.Padding为其LeftTopRightBottom属性的值为10的, 则该单元格的内容将在具有空格的单元格中间绘制文本框边缘与单元格边缘之间的10像素。For example, if you set Padding on a DataGridViewTextBoxCell to a System.Windows.Forms.Padding that has a value of 10 for its Left, Top, Right, and Bottom properties, the content of the cell is drawn in the middle of the cell with a space of 10 pixels between the edges of the text box and the edges of the cell.

适用于

另请参阅