DataGridViewCellStyle.Padding 屬性

定義

取得或設定介於 DataGridViewCell 的邊緣與其內容之間的空格。

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

屬性值

Padding,表示介於 DataGridViewCell 的邊緣與其內容之間的空格。

範例

下列程式碼範例說明在包含擁有者繪製資料列的 控制項中使用 DataGridView 此屬性。 每個資料列都會顯示跨越一般儲存格內容下方資料列之整個寬度的文字。 屬性 Padding 可用來提供此文字的額外空間。 在此範例中,所需的額外高度會儲存在稱為 CUSTOM_CONTENT_HEIGHT 的常數中。

此程式碼範例是較大範例的一部分。 如需完整的範例,請參閱How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control

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

備註

Padding設定 屬性會影響繪製 的編輯控制項 DataGridViewCell 的位置。 例如,如果您將 設定 PaddingDataGridViewTextBoxCellSystem.Windows.Forms.Padding 值為 10 的 ,其 LeftTopRightBottom 屬性,則儲存格的內容會在儲存格中間繪製,在文字方塊邊緣與儲存格邊緣之間的空格為 10 圖元。

適用於

另請參閱