DataGridViewCellStyle.Padding Właściwość

Definicja

Pobiera lub ustawia odstęp między krawędzią obiektu DataGridViewCell a jego zawartością.

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

Wartość właściwości

Obiekt Padding reprezentujący przestrzeń między krawędzią obiektu a jego zawartością DataGridViewCell .

Przykłady

Poniższy przykład kodu ilustruje użycie tej właściwości w kontrolce zawierającej DataGridView wiersze rysowane przez właściciela. Każdy wiersz wyświetla tekst obejmujący całą szerokość wiersza pod zwykłą zawartością komórki. Właściwość Padding jest używana do zapewnienia dodatkowego miejsca dla tego tekstu. W tym przykładzie wymagana dodatkowa wysokość jest przechowywana w stałej o nazwie CUSTOM_CONTENT_HEIGHT.

Ten przykład kodu jest częścią większego przykładu. Pełny przykład można znaleźć w temacie How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control (Instrukcje: dostosowywanie wyglądu wierszy w kontrolce 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

Uwagi

Padding Ustawienie właściwości wpływa na to, gdzie jest rysowana kontrolka edycjiDataGridViewCell. Jeśli na przykład ustawisz Padding dla DataGridViewTextBoxCell obiektu System.Windows.Forms.Padding wartość 10 dla jej Leftwłaściwości , Top, Righti Bottom , zawartość komórki jest rysowana w środku komórki z odstępem 10 pikseli między krawędziami pola tekstowego a krawędziami komórki.

Dotyczy

Zobacz też