Bagikan melalui


DataGridViewCellStyle.Padding Properti

Definisi

Mendapatkan atau mengatur spasi antara tepi dan DataGridViewCell kontennya.

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

Nilai Properti

Padding yang mewakili spasi antara tepi dan DataGridViewCell kontennya.

Contoh

Contoh kode berikut mengilustrasikan penggunaan properti ini dalam DataGridView kontrol yang berisi baris yang digambar pemilik. Setiap baris menampilkan teks yang mencakup seluruh lebar baris di bawah konten sel reguler. Properti Padding digunakan untuk menyediakan ruang ekstra untuk teks ini. Dalam contoh, tinggi ekstra yang diperlukan disimpan dalam konstanta yang disebut CUSTOM_CONTENT_HEIGHT.

Contoh kode ini adalah bagian dari contoh yang lebih besar. Untuk contoh lengkapnya, lihat Cara: Menyesuaikan Tampilan Baris di Kontrol 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

Keterangan

Padding Mengatur properti memengaruhi di mana kontrol pengeditan digambarDataGridViewCell. Misalnya, jika Anda mengatur Padding pada DataGridViewTextBoxCell ke System.Windows.Forms.Padding yang memiliki nilai 10 untuk Leftproperti , , Top, Rightdan Bottom , , dan , konten sel digambar di tengah sel dengan spasi 10 piksel di antara tepi kotak teks dan tepi sel.

Berlaku untuk

Lihat juga