DataGridViewPaintParts Enum

Definitie

Definieert waarden voor het opgeven van de delen van een DataGridViewCell die moeten worden geschilderd.

Deze opsomming ondersteunt een bitsgewijze combinatie van de waarden van de leden.

public enum class DataGridViewPaintParts
[System.Flags]
public enum DataGridViewPaintParts
[<System.Flags>]
type DataGridViewPaintParts = 
Public Enum DataGridViewPaintParts
Overname
DataGridViewPaintParts
Kenmerken

Velden

Name Waarde Description
None 0

Niets mag geschilderd worden.

Background 1

De achtergrond van de cel moet worden geschilderd.

Border 2

De rand van de cel moet worden geschilderd.

ContentBackground 4

De achtergrond van de celinhoud moet worden geschilderd.

ContentForeground 8

De voorgrond van de celinhoud moet worden geschilderd.

ErrorIcon 16

Het pictogram celfout moet worden geschilderd.

Focus 32

De focusrechthoek moet rond de cel worden geschilderd.

SelectionBackground 64

De achtergrond van de cel moet worden geschilderd wanneer de cel is geselecteerd.

All 127

Alle delen van de cel moeten worden geschilderd.

Voorbeelden

Het volgende codevoorbeeld illustreert het gebruik van dit type. Dit voorbeeld maakt deel uit van een groter voorbeeld dat beschikbaar is in Hoe to: Het uiterlijk van rijen aanpassen in het Windows Forms DataGridView-besturingselement.

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

Opmerkingen

Deze opsomming wordt gebruikt door de beveiligde DataGridViewCell.Paint methode en door handlers voor het CellPaintingbesturingselement RowPrePainten RowPostPaint gebeurtenissen van het DataGridView besturingselement.

Van toepassing op

Zie ook