Επεξεργασία

Κοινή χρήση μέσω


DataGridViewCellStyle.Padding Property

Definition

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

Property Value

A Padding that represents the space between the edge of a DataGridViewCell and its content.

Examples

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. The Padding property is used to provide the extra space for this text. 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. 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

Remarks

Setting the Padding property affects where the editing control of the DataGridViewCell is drawn. 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.

Applies to

See also