閱讀英文

共用方式為


DataGridViewPaintParts 列舉

定義

定義值來指定要繪製的 DataGridViewCell 部分。

此列舉支援其成員值的位元組合。

C#
[System.Flags]
public enum DataGridViewPaintParts
繼承
DataGridViewPaintParts
屬性

欄位

名稱 Description
All 127

儲存格的所有部分都應該繪製。

Background 1

應該繪製儲存格的背景。

Border 2

應該繪製儲存格的框線。

ContentBackground 4

應該繪製儲存格內容的背景。

ContentForeground 8

應該繪製儲存格內容的前景。

ErrorIcon 16

應該繪製儲存格錯誤圖示。

Focus 32

應該在儲存格的周圍繪製焦點矩形。

None 0

不應該繪製任何項目。

SelectionBackground 64

當選取儲存格時,應該繪製儲存格的背景。

範例

下列程式碼範例說明如何使用此類型。 此範例是How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control中較大型範例的一部分。

C#
// Paints the custom selection background for selected rows.
void dataGridView1_RowPrePaint(object sender,
        DataGridViewRowPrePaintEventArgs e)
{
    // Do not automatically paint the focus rectangle.
    e.PaintParts &= ~DataGridViewPaintParts.Focus;

    // Determine whether the cell should be painted
    // with the custom selection background.
    if ((e.State & DataGridViewElementStates.Selected) ==
                DataGridViewElementStates.Selected)
    {
        // Calculate the bounds of the row.
        Rectangle rowBounds = new Rectangle(
            this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
            this.dataGridView1.Columns.GetColumnsWidth(
                DataGridViewElementStates.Visible) -
            this.dataGridView1.HorizontalScrollingOffset + 1,
            e.RowBounds.Height);

        // Paint the custom selection background.
        using (Brush backbrush =
            new System.Drawing.Drawing2D.LinearGradientBrush(rowBounds,
                this.dataGridView1.DefaultCellStyle.SelectionBackColor,
                e.InheritedRowStyle.ForeColor,
                System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
        {
            e.Graphics.FillRectangle(backbrush, rowBounds);
        }
    }
}

備註

這個列舉是由受保護 DataGridViewCell.Paint 方法和 控制項之 CellPaintingRowPrePaintRowPostPaint 事件的 DataGridView 處理常式所使用。

適用於

產品 版本
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另請參閱