Aracılığıyla paylaş


DataGridViewCellPaintingEventArgs Sınıf

Tanım

CellPainting olayı için veriler sağlar.

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

Örnekler

Aşağıdaki kod örneğinde bu türün kullanımı gösterilmektedir. Daha fazla bilgi için bkz . Nasıl yapılır: Windows Forms DataGridView Denetiminde Hücrelerin Görünümünü Özelleştirme.

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

Açıklamalar

OlayCellPainting, üzerinde DataGridViewgörünen her DataGridViewCell biri için oluşturulur. Performansı geliştirmek için içindeki özelliklerini DataGridViewCellPaintingEventArgs , içindeki bir hücreye doğrudan erişmek yerine hücrenin DataGridViewgörünümünü değiştirmek üzere ayarlayın. Hücreyi el ile boyarsanız özelliğini olarak trueayarlayınHandledEventArgs.Handled. olarak ayarlanmazsa HandledEventArgs.Handledtrue, hücre özelleştirmelerinizin üzerine boyanacaktır.

Oluşturucular

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

DataGridViewCellPaintingEventArgs sınıfının yeni bir örneğini başlatır.

Özellikler

Name Description
AdvancedBorderStyle

Geçerli DataGridViewCellöğesinin kenarlık stilini alır.

CellBounds

Geçerli DataGridViewCellöğesinin sınırlarını alın.

CellStyle

Geçerli DataGridViewCellhücre stilini alır.

ClipBounds

Yeniden boyanması DataGridView gereken alanı alır.

ColumnIndex

Geçerli DataGridViewCellsütun dizinini alır.

ErrorText

Geçerli DataGridViewCelliçin hata iletisini temsil eden bir dize alır.

FormattedValue

Geçerli DataGridViewCelldeğerinin biçimlendirilmiş değerini alır.

Graphics

Graphics Geçerli DataGridViewCellöğesini boyamak için kullanılan öğesini alır.

Handled

Olay işleyicisinin olayı tamamen işleyip işlemediğini veya sistemin kendi işlemeye devam edip etmeyeceğini belirten bir değer alır veya ayarlar.

(Devralındığı yer: HandledEventArgs)
PaintParts

Boyanacak hücre parçaları.

RowIndex

Geçerli DataGridViewCellöğesinin satır dizinini alır.

State

Geçerli DataGridViewCelldurumunu alır.

Value

Geçerli DataGridViewCelldeğerini alır.

Yöntemler

Name Description
Equals(Object)

Belirtilen nesnenin geçerli nesneye eşit olup olmadığını belirler.

(Devralındığı yer: Object)
GetHashCode()

Varsayılan karma işlevi işlevi görür.

(Devralındığı yer: Object)
GetType()

Geçerli örneğin Type alır.

(Devralındığı yer: Object)
MemberwiseClone()

Geçerli Objectbasit bir kopyasını oluşturur.

(Devralındığı yer: Object)
Paint(Rectangle, DataGridViewPaintParts)

Belirtilen sınırlardaki alan için hücrenin belirtilen bölümlerini boyar.

PaintBackground(Rectangle, Boolean)

Belirtilen sınırlardaki alanın hücre arka planını boyar.

PaintContent(Rectangle)

Belirtilen sınırlardaki alanın hücre içeriğini boyar.

ToString()

Geçerli nesneyi temsil eden bir dize döndürür.

(Devralındığı yer: Object)

Şunlara uygulanır

Ayrıca bkz.