DataGridViewCellStyle.Padding Propriedade

Definição

Obtém ou define o espaço entre a borda de um DataGridViewCell e seu conteúdo.

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

Valor da propriedade

Padding

Um Padding que representa o espaço entre a borda de um DataGridViewCell e seu conteúdo.

Exemplos

O exemplo de código a seguir ilustra o uso dessa propriedade em um DataGridView controle que contém linhas desenhadas pelo proprietário. Cada linha exibe texto que abrange toda a largura da linha abaixo do conteúdo da célula regular. A Padding propriedade é usada para fornecer o espaço extra para este texto. No exemplo, a altura extra necessária é armazenada em uma constante chamada CUSTOM_CONTENT_HEIGHT.

Este exemplo de código faz parte de um exemplo maior. Para obter o exemplo completo, consulte Como personalizar a aparência das linhas no controle Windows Forms DataGridView.

// 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

Comentários

Definir a Padding propriedade afeta onde o controle de edição do DataGridViewCell é desenhado. Por exemplo, se você definir Padding em um DataGridViewTextBoxCell System.Windows.Forms.Padding valor de 10 para sua Left, TopRighte Bottom propriedades, o conteúdo da célula é desenhado no meio da célula com um espaço de 10 pixels entre as bordas da caixa de texto e as bordas da célula.

Aplica-se a

Confira também