DataGridViewPaintParts Enumeração

Definição

Define os valores para especificar as partes de um DataGridViewCell que serão pintadas.

Essa enumeração dá suporte a uma combinação bit a bit dos valores de membro.

public enum class DataGridViewPaintParts
[System.Flags]
public enum DataGridViewPaintParts
[<System.Flags>]
type DataGridViewPaintParts = 
Public Enum DataGridViewPaintParts
Herança
DataGridViewPaintParts
Atributos

Campos

All 127

Todas as partes da célula devem ser pintadas.

Background 1

A tela de fundo da célula deve ser pintada.

Border 2

A borda da célula deve ser pintada.

ContentBackground 4

A tela de fundo do conteúdo da célula deve ser pintada.

ContentForeground 8

O primeiro plano do conteúdo da célula deve ser pintado.

ErrorIcon 16

O ícone de erro de célula deve ser pintado.

Focus 32

O retângulo de foco deve ser pintado em torno da célula.

None 0

Nada deve ser pintado.

SelectionBackground 64

A tela de fundo da célula deve ser pintada quando a célula é selecionada.

Exemplos

O exemplo de código a seguir ilustra o uso desse tipo. Este exemplo faz parte de um exemplo maior disponível em Como personalizar a aparência de linhas no controle Windows Forms DataGridView.

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

Comentários

Essa enumeração é usada pelo método protegido DataGridViewCell.Paint e por manipuladores para os CellPaintingeventos , RowPrePainte RowPostPaint do DataGridView controle .

Aplica-se a

Confira também