Partager via


DataGridViewCellStyle.Padding Propriété

Définition

Obtient ou définit l’espace entre le bord d’un DataGridViewCell et son contenu.

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

Valeur de propriété

Qui Padding représente l’espace entre le bord d’un DataGridViewCell et son contenu.

Exemples

L’exemple de code suivant illustre l’utilisation de cette propriété dans un DataGridView contrôle qui contient des lignes dessinées par le propriétaire. Chaque ligne affiche du texte qui s’étend sur toute la largeur de la ligne sous le contenu de cellule standard. La Padding propriété est utilisée pour fournir l’espace supplémentaire pour ce texte. Dans l’exemple, la hauteur supplémentaire requise est stockée dans une constante appelée CUSTOM_CONTENT_HEIGHT.

Cet exemple de code fait partie d’un exemple plus large. Pour obtenir l’exemple complet, consultez Comment : personnaliser l’apparence des lignes dans le contrôle DataGridView Windows Forms.

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

Remarques

La définition de la Padding propriété affecte l’emplacement où le contrôle d’édition du fichier DataGridViewCell est dessiné. Par exemple, si vous définissez Padding sur un DataGridViewTextBoxCellSystem.Windows.Forms.Padding qui a une valeur de 10 pour ses Leftpropriétés , Topet RightBottom son contenu, le contenu de la cellule est dessiné au milieu de la cellule avec un espace de 10 pixels entre les bords de la zone de texte et les bords de la cellule.

S’applique à

Voir aussi