DataGridViewPaintParts Enumeration

Definition

Definiert Werte zum Angeben der Teile einer DataGridViewCell, die gezeichnet werden sollen.

Diese Enumeration unterstützt eine bitweise Kombination ihrer Memberwerte.

public enum class DataGridViewPaintParts
[System.Flags]
public enum DataGridViewPaintParts
[<System.Flags>]
type DataGridViewPaintParts = 
Public Enum DataGridViewPaintParts
Vererbung
DataGridViewPaintParts
Attribute

Felder

Name Wert Beschreibung
None 0

Nichts sollte gezeichnet werden.

Background 1

Der Hintergrund der Zelle sollte gezeichnet werden.

Border 2

Der Rahmen der Zelle sollte gezeichnet werden.

ContentBackground 4

Der Hintergrund des Zellinhalts sollte gezeichnet werden.

ContentForeground 8

Der Vordergrund des Zellinhalts sollte gezeichnet werden.

ErrorIcon 16

Das Zellenfehlersymbol sollte gezeichnet werden.

Focus 32

Das Fokusrechteck sollte um die Zelle gezeichnet werden.

SelectionBackground 64

Der Hintergrund der Zelle sollte gezeichnet werden, wenn die Zelle ausgewählt ist.

All 127

Alle Teile der Zelle sollten gezeichnet werden.

Beispiele

Im folgenden Codebeispiel wird die Verwendung dieses Typs veranschaulicht. Dieses Beispiel ist Teil eines größeren Beispiels, das in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control verfügbar ist.

// 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);
        }
    }
}
' Paints the custom selection background for selected rows.
Sub dataGridView1_RowPrePaint(ByVal sender As Object, _
    ByVal e As DataGridViewRowPrePaintEventArgs) _
    Handles dataGridView1.RowPrePaint

    ' Do not automatically paint the focus rectangle.
    e.PaintParts = e.PaintParts And Not DataGridViewPaintParts.Focus

    ' Determine whether the cell should be painted with the 
    ' custom selection background.
    If (e.State And DataGridViewElementStates.Selected) = _
        DataGridViewElementStates.Selected Then

        ' Calculate the bounds of the row.
        Dim rowBounds As New Rectangle( _
            Me.dataGridView1.RowHeadersWidth, e.RowBounds.Top, _
            Me.dataGridView1.Columns.GetColumnsWidth( _
            DataGridViewElementStates.Visible) - _
            Me.dataGridView1.HorizontalScrollingOffset + 1, _
            e.RowBounds.Height)

        ' Paint the custom selection background.
        Dim backbrush As New _
            System.Drawing.Drawing2D.LinearGradientBrush(rowBounds, _
            Me.dataGridView1.DefaultCellStyle.SelectionBackColor, _
            e.InheritedRowStyle.ForeColor, _
            System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
        Try
            e.Graphics.FillRectangle(backbrush, rowBounds)
        Finally
            backbrush.Dispose()
        End Try
    End If

End Sub

Hinweise

Diese Aufzählung wird von der geschützten DataGridViewCell.Paint Methode und von Handlern für die CellPainting, RowPrePaintund RowPostPaint Ereignisse des DataGridView Steuerelements verwendet.

Gilt für:

Weitere Informationen