Sdílet prostřednictvím


DataGridViewCellStyle.Padding Vlastnost

Definice

Získá nebo nastaví prostor mezi okrajem DataGridViewCell a jeho obsahem.

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

Hodnota vlastnosti

A Padding , který představuje prostor mezi okrajem a jeho obsahem DataGridViewCell .

Příklady

Následující příklad kódu ukazuje použití této vlastnosti v ovládacím DataGridView prvku, který obsahuje řádky nakreslené vlastníkem. Každý řádek zobrazuje text, který pokrývá celou šířku řádku pod obsahem běžné buňky. Vlastnost Padding slouží k poskytnutí nadbytečného místa pro tento text. V příkladu je vyžadována dodatečná výška uložena v konstantě s názvem CUSTOM_CONTENT_HEIGHT.

Tento příklad kódu je součástí většího příkladu. Úplný příklad naleznete v tématu Postupy: Přizpůsobení vzhledu řádků v ovládacím prvku 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

Poznámky

Padding Nastavení vlastnosti má vliv na to, kde je nakreslen ovládací prvek DataGridViewCell pro úpravy. Pokud například nastavíte Padding hodnotu DataGridViewTextBoxCellSystem.Windows.Forms.Padding 10 pro jeho Left, TopRighta Bottom vlastnosti, obsah buňky se nakreslí uprostřed buňky s mezerou 10 pixelů mezi okraji textového pole a okraji buňky.

Platí pro

Viz také