DataGridViewPaintParts Énumération

Définition

Définit des valeurs pour spécifier les parties d’un DataGridViewCell à peindre.

Cette énumération prend en charge une combinaison au niveau du bit de ses valeurs membres.

public enum class DataGridViewPaintParts
[System.Flags]
public enum DataGridViewPaintParts
[<System.Flags>]
type DataGridViewPaintParts = 
Public Enum DataGridViewPaintParts
Héritage
DataGridViewPaintParts
Attributs

Champs

Nom Valeur Description
None 0

Rien ne devrait être peint.

Background 1

L’arrière-plan de la cellule doit être peint.

Border 2

La bordure de la cellule doit être peinte.

ContentBackground 4

L’arrière-plan du contenu de cellule doit être peint.

ContentForeground 8

Le premier plan du contenu de la cellule doit être peint.

ErrorIcon 16

L’icône d’erreur de cellule doit être peinte.

Focus 32

Le rectangle de focus doit être peint autour de la cellule.

SelectionBackground 64

L’arrière-plan de la cellule doit être peint lorsque la cellule est sélectionnée.

All 127

Toutes les parties de la cellule doivent être peintes.

Exemples

L’exemple de code suivant illustre l’utilisation de ce type. Cet exemple fait partie d’un exemple plus large disponible dans How to : Customize the Appearance of Rows in the Windows Forms DataGridView Control.

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

Remarques

Cette énumération est utilisée par la méthode protégée DataGridViewCell.Paint et par les gestionnaires pour les événements CellPaintinget RowPrePaint les RowPostPaintévénements du DataGridView contrôle.

S’applique à

Voir aussi