DataGridViewRowPrePaintEventArgs Klasa

Definicja

Udostępnia dane dla zdarzenia RowPrePaint.

public ref class DataGridViewRowPrePaintEventArgs : System::ComponentModel::HandledEventArgs
public class DataGridViewRowPrePaintEventArgs : System.ComponentModel.HandledEventArgs
type DataGridViewRowPrePaintEventArgs = class
    inherit HandledEventArgs
Public Class DataGridViewRowPrePaintEventArgs
Inherits HandledEventArgs
Dziedziczenie
DataGridViewRowPrePaintEventArgs

Przykłady

W poniższym przykładzie kodu pokazano, jak obsłużyć zdarzenie w RowPrePaint celu narysowania niestandardowego tła dla zaznaczonych komórek. Ten przykład kodu jest częścią większego przykładu przedstawionego 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

Zdarzenie RowPrePaint występuje, zanim wiersz zostanie namalowany na kontrolce DataGridView . RowPrePaint umożliwia ręczne dostosowanie wyglądu wiersza przed namalowanie któregokolwiek z komórek w wierszu. Jest to przydatne, jeśli chcesz dostosować wiersz, na przykład w celu utworzenia wiersza, w którym zawartość jednej kolumny obejmuje wiele kolumn. Użyj właściwości w pliku , DataGridViewRowPrePaintEventArgs aby uzyskać ustawienia wiersza bez bezpośredniego uzyskiwania dostępu do wiersza w elemecie DataGridView.

Konstruktory

DataGridViewRowPrePaintEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, String, DataGridViewCellStyle, Boolean, Boolean)

Inicjuje nowe wystąpienie klasy DataGridViewRowPrePaintEventArgs.

Właściwości

ClipBounds

Pobiera lub ustawia obszar, DataGridView który musi zostać przemalowany.

ErrorText

Pobiera ciąg reprezentujący komunikat o błędzie dla bieżącego DataGridViewRowelementu .

Graphics

Graphics Pobiera element używany do malowania bieżącego DataGridViewRow.

Handled

Pobiera lub ustawia wartość wskazującą, czy program obsługi zdarzeń całkowicie obsłuży zdarzenie, czy też system powinien kontynuować własne przetwarzanie.

(Odziedziczone po HandledEventArgs)
InheritedRowStyle

Pobiera styl komórki zastosowany do wiersza.

IsFirstDisplayedRow

Pobiera wartość wskazującą, czy bieżący wiersz jest pierwszym wierszem wyświetlanym obecnie w elemencie DataGridView.

IsLastVisibleRow

Pobiera wartość wskazującą, czy bieżący wiersz jest ostatnim widocznym wierszem w elemencie DataGridView.

PaintParts

Części komórek, które mają być malowane.

RowBounds

Pobierz granice bieżącego DataGridViewRowobiektu .

RowIndex

Pobiera indeks bieżącego DataGridViewRowobiektu .

State

Pobiera stan bieżącej DataGridViewRowwartości .

Metody

DrawFocus(Rectangle, Boolean)

Rysuje prostokąt fokusu wokół określonych granic.

Equals(Object)

Określa, czy dany obiekt jest taki sam, jak bieżący obiekt.

(Odziedziczone po Object)
GetHashCode()

Służy jako domyślna funkcja skrótu.

(Odziedziczone po Object)
GetType()

Type Pobiera bieżące wystąpienie.

(Odziedziczone po Object)
MemberwiseClone()

Tworzy płytkią kopię bieżącego Objectelementu .

(Odziedziczone po Object)
PaintCells(Rectangle, DataGridViewPaintParts)

Maluje określone części komórek dla obszaru w określonych granicach.

PaintCellsBackground(Rectangle, Boolean)

Maluje tła komórek dla obszaru w określonych granicach.

PaintCellsContent(Rectangle)

Maluje zawartość komórki dla obszaru w określonych granicach.

PaintHeader(Boolean)

Maluje cały nagłówek wiersza bieżącego DataGridViewRowelementu .

PaintHeader(DataGridViewPaintParts)

Maluje określone części nagłówka wiersza bieżącego wiersza.

ToString()

Zwraca ciąg reprezentujący bieżący obiekt.

(Odziedziczone po Object)

Dotyczy

Zobacz też