Bagikan melalui


DataGridViewCellPaintingEventArgs Kelas

Definisi

Menyediakan data untuk peristiwa tersebut CellPainting .

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

Contoh

Contoh kode berikut mengilustrasikan penggunaan jenis ini. Untuk informasi selengkapnya, lihat Cara: Menyesuaikan Tampilan Sel di Kontrol DataGridView Formulir Windows.

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

Keterangan

Peristiwa CellPainting dinaikkan untuk masing-masing DataGridViewCell yang terlihat pada DataGridView. Untuk meningkatkan performa, atur properti dalam DataGridViewCellPaintingEventArgs untuk mengubah tampilan sel alih-alih langsung mengakses sel di DataGridView. Jika Anda melukis sel secara manual, atur properti ke HandledEventArgs.Handledtrue. Jika Anda tidak mengatur HandledEventArgs.Handled ke true, sel akan melukis kustomisasi Anda.

Konstruktor

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

Menginisialisasi instans baru dari kelas DataGridViewCellPaintingEventArgs.

Properti

Nama Deskripsi
AdvancedBorderStyle

Mendapatkan gaya batas saat ini DataGridViewCell.

CellBounds

Dapatkan batasan dari saat ini DataGridViewCell.

CellStyle

Mendapatkan gaya sel saat ini DataGridViewCell.

ClipBounds

Mendapatkan area DataGridView yang perlu dicat ulang.

ColumnIndex

Mendapatkan indeks kolom dari .DataGridViewCell

ErrorText

Mendapatkan string yang mewakili pesan kesalahan untuk .DataGridViewCell

FormattedValue

Mendapatkan nilai yang diformat dari .DataGridViewCell

Graphics

Mendapatkan digunakan Graphics untuk melukis arus DataGridViewCell.

Handled

Mendapatkan atau menetapkan nilai yang menunjukkan apakah penanganan aktivitas telah sepenuhnya menangani peristiwa atau apakah sistem harus melanjutkan pemrosesannya sendiri.

(Diperoleh dari HandledEventArgs)
PaintParts

Bagian sel yang akan dicat.

RowIndex

Mendapatkan indeks baris dari .DataGridViewCell

State

Mendapatkan status saat ini DataGridViewCell.

Value

Mendapatkan nilai dari .DataGridViewCell

Metode

Nama Deskripsi
Equals(Object)

Menentukan apakah objek yang ditentukan sama dengan objek saat ini.

(Diperoleh dari Object)
GetHashCode()

Berfungsi sebagai fungsi hash default.

(Diperoleh dari Object)
GetType()

Mendapatkan Type instans saat ini.

(Diperoleh dari Object)
MemberwiseClone()

Membuat salinan dangkal dari Objectsaat ini.

(Diperoleh dari Object)
Paint(Rectangle, DataGridViewPaintParts)

Mengecat bagian sel yang ditentukan untuk area dalam batas yang ditentukan.

PaintBackground(Rectangle, Boolean)

Mengecat latar belakang sel untuk area dalam batas yang ditentukan.

PaintContent(Rectangle)

Mengecat konten sel untuk area dalam batas yang ditentukan.

ToString()

Mengembalikan string yang mewakili objek saat ini.

(Diperoleh dari Object)

Berlaku untuk

Lihat juga