DataGridViewPaintParts Enumerazione

Definizione

Definisce i valori per specificare le parti di un DataGridViewCell da disegnare.

Questa enumerazione supporta una combinazione bit per bit dei rispettivi valori dei membri.

public enum class DataGridViewPaintParts
[System.Flags]
public enum DataGridViewPaintParts
[<System.Flags>]
type DataGridViewPaintParts = 
Public Enum DataGridViewPaintParts
Ereditarietà
DataGridViewPaintParts
Attributi

Campi

Nome Valore Descrizione
None 0

Niente deve essere dipinto.

Background 1

Lo sfondo della cella deve essere disegnato.

Border 2

Il bordo della cella deve essere disegnato.

ContentBackground 4

Lo sfondo del contenuto della cella deve essere disegnato.

ContentForeground 8

Il primo piano del contenuto della cella deve essere disegnato.

ErrorIcon 16

L'icona di errore della cella deve essere disegnata.

Focus 32

Il rettangolo dello stato attivo deve essere disegnato intorno alla cella.

SelectionBackground 64

Lo sfondo della cella deve essere disegnato quando la cella è selezionata.

All 127

Tutte le parti della cella devono essere disegnate.

Esempio

Nell'esempio di codice seguente viene illustrato l'uso di questo tipo. Questo esempio fa parte di un esempio più ampio disponibile in Procedura: Personalizzare l'aspetto delle righe nel controllo DataGridView di Windows Form.

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

Commenti

Questa enumerazione viene utilizzata dal metodo protetto DataGridViewCell.Paint e dai gestori per gli CellPaintingeventi , RowPrePainte RowPostPaint del DataGridView controllo .

Si applica a

Vedi anche