DataGridViewCellPaintingEventArgs 클래스

정의

CellPainting 이벤트에 대한 데이터를 제공합니다.

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

예제

다음 코드 예제에서는이 형식의 사용을 보여 줍니다. 자세한 내용은 방법: 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

설명

합니다 CellPainting 각각에 대 한 이벤트가 발생 DataGridViewCell 에 표시 되는 DataGridView합니다. 성능 향상을 위해에서 속성을 설정를 DataGridViewCellPaintingEventArgs 셀에 직접 액세스 하는 대신 셀의 모양을 변경 하는 DataGridView합니다. 셀을 수동으로 그리는 경우에 설정 된 HandledEventArgs.Handled 속성을 true입니다. 설정 하지 않은 경우 HandledEventArgs.Handledtrue, 셀 사용자 지정 위에 그려집니다.

생성자

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

DataGridViewCellPaintingEventArgs 클래스의 새 인스턴스를 초기화합니다.

속성

AdvancedBorderStyle

현재 DataGridViewCell의 테두리 스타일을 가져옵니다.

CellBounds

현재 DataGridViewCell의 범위를 가져옵니다.

CellStyle

현재 DataGridViewCell의 셀 스타일을 가져옵니다.

ClipBounds

다시 그려야 하는 DataGridView의 영역을 가져옵니다.

ColumnIndex

현재 DataGridViewCell의 열 인덱스를 가져옵니다.

ErrorText

현재 DataGridViewCell에 대한 오류 메시지를 나타내는 문자열을 가져옵니다.

FormattedValue

현재 DataGridViewCell의 서식이 지정된 값을 가져옵니다.

Graphics

현재 Graphics을 그리는 데 사용되는 DataGridViewCell를 가져옵니다.

Handled

이벤트 처리기에서 이벤트를 완전히 처리했는지 아니면 시스템에서 처리를 계속해야 하는지를 나타내는 값을 가져오거나 설정합니다.

(다음에서 상속됨 HandledEventArgs)
PaintParts

그릴 셀 부분입니다.

RowIndex

현재 DataGridViewCell의 행 인덱스를 가져옵니다.

State

현재 DataGridViewCell의 상태를 가져옵니다.

Value

현재 DataGridViewCell의 값을 가져옵니다.

메서드

Equals(Object)

지정된 개체가 현재 개체와 같은지 확인합니다.

(다음에서 상속됨 Object)
GetHashCode()

기본 해시 함수로 작동합니다.

(다음에서 상속됨 Object)
GetType()

현재 인스턴스의 Type을 가져옵니다.

(다음에서 상속됨 Object)
MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.

(다음에서 상속됨 Object)
Paint(Rectangle, DataGridViewPaintParts)

지정된 범위의 영역에 지정된 셀 부분을 그립니다.

PaintBackground(Rectangle, Boolean)

지정된 범위의 영역에 셀 배경을 그립니다.

PaintContent(Rectangle)

지정된 범위의 영역에 셀 내용을 그립니다.

ToString()

현재 개체를 나타내는 문자열을 반환합니다.

(다음에서 상속됨 Object)

적용 대상

추가 정보