DataGridViewCellPaintingEventArgs Klasa

Definicja

Udostępnia dane dla zdarzenia CellPainting.

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

Przykłady

Poniższy przykład kodu ilustruje użycie tego typu. Aby uzyskać więcej informacji, zobacz How to: Customize the Appearance of Cells in the Windows Forms DataGridView Control (Instrukcje: dostosowywanie wyglądu komórek w kontrolce DataGridView) Windows Forms.

private void dataGridView1_CellPainting(object sender,
System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
{
    if (this.dataGridView1.Columns["ContactName"].Index ==
        e.ColumnIndex && e.RowIndex >= 0)
    {
        Rectangle newRect = new Rectangle(e.CellBounds.X + 1,
            e.CellBounds.Y + 1, e.CellBounds.Width - 4,
            e.CellBounds.Height - 4);

        using (
            Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
            backColorBrush = new SolidBrush(e.CellStyle.BackColor))
        {
            using (Pen gridLinePen = new Pen(gridBrush))
            {
                // Erase the cell.
                e.Graphics.FillRectangle(backColorBrush, e.CellBounds);

                // Draw the grid lines (only the right and bottom lines;
                // DataGridView takes care of the others).
                e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
                    e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
                    e.CellBounds.Bottom - 1);
                e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
                    e.CellBounds.Top, e.CellBounds.Right - 1,
                    e.CellBounds.Bottom);

                // Draw the inset highlight box.
                e.Graphics.DrawRectangle(Pens.Blue, newRect);

                // Draw the text content of the cell, ignoring alignment.
                if (e.Value != null)
                {
                    e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
                        Brushes.Crimson, e.CellBounds.X + 2,
                        e.CellBounds.Y + 2, StringFormat.GenericDefault);
                }
                e.Handled = true;
            }
        }
    }
}
Private Sub dataGridView1_CellPainting(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) _
    Handles dataGridView1.CellPainting

    If Me.dataGridView1.Columns("ContactName").Index = _
        e.ColumnIndex AndAlso e.RowIndex >= 0 Then

        Dim newRect As New Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, _
            e.CellBounds.Width - 4, e.CellBounds.Height - 4)
        Dim backColorBrush As New SolidBrush(e.CellStyle.BackColor)
        Dim gridBrush As New SolidBrush(Me.dataGridView1.GridColor)
        Dim gridLinePen As New Pen(gridBrush)

        Try

            ' Erase the cell.
            e.Graphics.FillRectangle(backColorBrush, e.CellBounds)

            ' Draw the grid lines (only the right and bottom lines;
            ' DataGridView takes care of the others).
            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, _
                e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, _
                e.CellBounds.Bottom - 1)
            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, _
                e.CellBounds.Top, e.CellBounds.Right - 1, _
                e.CellBounds.Bottom)

            ' Draw the inset highlight box.
            e.Graphics.DrawRectangle(Pens.Blue, newRect)

            ' Draw the text content of the cell, ignoring alignment.
            If (e.Value IsNot Nothing) Then
                e.Graphics.DrawString(CStr(e.Value), e.CellStyle.Font, _
                Brushes.Crimson, e.CellBounds.X + 2, e.CellBounds.Y + 2, _
                StringFormat.GenericDefault)
            End If
            e.Handled = True

        Finally
            gridLinePen.Dispose()
            gridBrush.Dispose()
            backColorBrush.Dispose()
        End Try

    End If

End Sub

Uwagi

Zdarzenie CellPainting jest wywoływane dla każdego DataGridViewCell elementu widocznego na obiekcie DataGridView. Aby poprawić wydajność, ustaw właściwości w obiekcie DataGridViewCellPaintingEventArgs , aby zmienić wygląd komórki zamiast bezpośrednio uzyskiwać dostęp do komórki w obiekcie DataGridView. Jeśli ręcznie malujesz komórkę, ustaw HandledEventArgs.Handled właściwość na truewartość . Jeśli nie ustawisz wartości HandledEventArgs.Handledtrue, komórka będzie malować swoje dostosowania.

Konstruktory

DataGridViewCellPaintingEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts)

Inicjuje nowe wystąpienie klasy DataGridViewCellPaintingEventArgs.

Właściwości

AdvancedBorderStyle

Pobiera styl obramowania bieżącego DataGridViewCellelementu .

CellBounds

Pobierz granice bieżącego DataGridViewCellelementu .

CellStyle

Pobiera styl komórki bieżącego DataGridViewCellelementu .

ClipBounds

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

ColumnIndex

Pobiera indeks kolumn bieżącego DataGridViewCellelementu .

ErrorText

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

FormattedValue

Pobiera sformatowaną wartość bieżącego DataGridViewCellelementu .

Graphics

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

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)
PaintParts

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

RowIndex

Pobiera indeks wierszy bieżącego DataGridViewCellelementu .

State

Pobiera stan bieżącej DataGridViewCellwartości .

Value

Pobiera wartość bieżącego DataGridViewCellelementu .

Metody

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 wartość bieżącego wystąpienia.

(Odziedziczone po Object)
MemberwiseClone()

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

(Odziedziczone po Object)
Paint(Rectangle, DataGridViewPaintParts)

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

PaintBackground(Rectangle, Boolean)

Maluje tło komórki dla obszaru w określonych granicach.

PaintContent(Rectangle)

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

ToString()

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

(Odziedziczone po Object)

Dotyczy

Zobacz też