DataGridViewPaintParts Enumeración

Definición

Define valores para especificar las partes de un DataGridViewCell que se pintarán.Defines values for specifying the parts of a DataGridViewCell that are to be painted.

Esta enumeración tiene el atributo FlagsAttribute, que permite una combinación bit a bit de sus valores de miembro.

public enum class DataGridViewPaintParts
[System.Flags]
public enum DataGridViewPaintParts
type DataGridViewPaintParts = 
Public Enum DataGridViewPaintParts
Herencia
DataGridViewPaintParts
Atributos

Campos

All 127

Se deben pintar todas las partes de la celda.All parts of the cell should be painted.

Background 1

Se debe pintar el fondo de la celda.The background of the cell should be painted.

Border 2

Se debe pintar el borde de la celda.The border of the cell should be painted.

ContentBackground 4

Se debe pintar el fondo del contenido de la celda.The background of the cell content should be painted.

ContentForeground 8

Se debe pintar el primer plano del contenido de la celda.The foreground of the cell content should be painted.

ErrorIcon 16

Se debe pintar el icono de error de celda.The cell error icon should be painted.

Focus 32

Se debe pintar el rectángulo de foco alrededor de la celda.The focus rectangle should be painted around the cell.

None 0

No se debe pintar nada.Nothing should be painted.

SelectionBackground 64

Se debe pintar el fondo de la celda cuando la celda esté seleccionada.The background of the cell should be painted when the cell is selected.

Ejemplos

En el ejemplo de código siguiente se muestra el uso de este tipo.The following code example illustrates the use of this type. Este ejemplo forma parte de un ejemplo más grande disponible en cómo: Personalice la apariencia de las filas en el controlDataGridView Windows Forms.This example is part of a larger example available in 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

Comentarios

Esta enumeración la usan el método DataGridViewCell.Paint protegido y los controladores para los CellPaintingeventos, RowPrePainty RowPostPaint del DataGridView control.This enumeration is used by the protected DataGridViewCell.Paint method and by handlers for the CellPainting, RowPrePaint, and RowPostPaint events of the DataGridView control.

Se aplica a

Consulte también: