DataGridViewPaintParts Wyliczenie

Definicja

Definiuje wartości służące do określania części DataGridViewCell , które mają być malowane.

To wyliczenie obsługuje bitową kombinację jego wartości składowych.

public enum class DataGridViewPaintParts
[System.Flags]
public enum DataGridViewPaintParts
[<System.Flags>]
type DataGridViewPaintParts = 
Public Enum DataGridViewPaintParts
Dziedziczenie
DataGridViewPaintParts
Atrybuty

Pola

All 127

Wszystkie części komórki powinny być malowane.

Background 1

Tło komórki należy malować.

Border 2

Obramowanie komórki powinno być malowane.

ContentBackground 4

Tło zawartości komórki należy malować.

ContentForeground 8

Na pierwszym planie zawartości komórki należy malować.

ErrorIcon 16

Ikona błędu komórki powinna być malowana.

Focus 32

Prostokąt fokusu powinien być malowany wokół komórki.

None 0

Nic nie powinno być malowane.

SelectionBackground 64

Tło komórki należy malować po wybraniu komórki.

Przykłady

Poniższy przykład kodu ilustruje użycie tego typu. Ten przykład jest częścią większego przykładu dostępnego w temacie How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control (Dostosowywanie wyglądu wierszy w kontrolce 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

Uwagi

To wyliczenie jest używane przez chronioną DataGridViewCell.Paint metodę i programy obsługi dla CellPaintingRowPrePaintzdarzeń , i RowPostPaint kontrolki DataGridView .

Dotyczy

Zobacz też