DataGridViewCellPaintingEventArgs Třída

Definice

Poskytuje data pro událost CellPainting.

public ref class DataGridViewCellPaintingEventArgs : System::ComponentModel::HandledEventArgs
public class DataGridViewCellPaintingEventArgs : System.ComponentModel.HandledEventArgs
type DataGridViewCellPaintingEventArgs = class
    inherit HandledEventArgs
Public Class DataGridViewCellPaintingEventArgs
Inherits HandledEventArgs
Dědičnost
DataGridViewCellPaintingEventArgs

Příklady

Následující příklad kódu ukazuje použití tohoto typu. Další informace naleznete v tématu Postupy: Přizpůsobení vzhledu buněk v ovládacím prvku model Windows Forms DataGridView.

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

Poznámky

Událost CellPainting je vyvolána pro každou DataGridViewCell událost, která je viditelná na DataGridView. Pokud chcete zvýšit výkon, nastavením vlastností v objektu DataGridViewCellPaintingEventArgs změňte vzhled buňky místo přímého přístupu k buňce v objektu DataGridView. Pokud buňku malujete ručně, nastavte HandledEventArgs.Handled vlastnost na true. Pokud nenastavíte HandledEventArgs.Handled možnost true, buňka přemaluje vaše vlastní nastavení.

Konstruktory

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

Inicializuje novou instanci DataGridViewCellPaintingEventArgs třídy .

Vlastnosti

AdvancedBorderStyle

Získá styl ohraničení aktuální DataGridViewCell.

CellBounds

Získá hranice aktuálního DataGridViewCell.

CellStyle

Získá styl buňky aktuální DataGridViewCell.

ClipBounds

Získá oblast DataGridView , která je třeba překreslovat.

ColumnIndex

Získá index sloupce aktuální DataGridViewCell.

ErrorText

Získá řetězec, který představuje chybovou zprávu pro aktuální DataGridViewCell.

FormattedValue

Získá formátovanou hodnotu aktuálního DataGridViewCellobjektu .

Graphics

Graphics Získá objekt použitý k vykreslení aktuálního DataGridViewCellobjektu .

Handled

Získá nebo nastaví hodnotu, která označuje, zda obslužná rutina události zcela zpracovala událost nebo zda systém má pokračovat ve vlastním zpracování.

(Zděděno od HandledEventArgs)
PaintParts

Části buněk, které mají být malovány.

RowIndex

Získá index řádku aktuální DataGridViewCell.

State

Získá stav aktuálního DataGridViewCellobjektu .

Value

Získá hodnotu aktuálního DataGridViewCellobjektu .

Metody

Equals(Object)

Určí, zda se zadaný objekt rovná aktuálnímu objektu.

(Zděděno od Object)
GetHashCode()

Slouží jako výchozí hashovací funkce.

(Zděděno od Object)
GetType()

Type Získá z aktuální instance.

(Zděděno od Object)
MemberwiseClone()

Vytvoří mělkou kopii aktuálního Objectsouboru .

(Zděděno od Object)
Paint(Rectangle, DataGridViewPaintParts)

Vykreslí zadané části buňky pro oblast v zadaných mezích.

PaintBackground(Rectangle, Boolean)

Vykreslí pozadí buňky pro oblast v zadaných mezích.

PaintContent(Rectangle)

Vykreslí obsah buňky pro oblast v zadaných mezích.

ToString()

Vrátí řetězec, který představuje aktuální objekt.

(Zděděno od Object)

Platí pro

Viz také