DataGridViewCellPaintingEventArgs DataGridViewCellPaintingEventArgs DataGridViewCellPaintingEventArgs DataGridViewCellPaintingEventArgs Class

정의

CellPainting 이벤트에 대한 데이터를 제공합니다.Provides data for the CellPainting event.

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

예제

다음 코드 예제에서는이 형식의 사용을 보여 줍니다.The following code example illustrates the use of this type. 자세한 내용은 방법: Windows Forms DataGridView 컨트롤에서 셀 모양 사용자 지정합니다.For more information, see How to: Customize the Appearance of Cells in the Windows Forms DataGridView Control.

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합니다.The CellPainting event is raised for each DataGridViewCell that is visible on a DataGridView. 성능 향상을 위해에서 속성을 설정를 DataGridViewCellPaintingEventArgs 셀에 직접 액세스 하는 대신 셀의 모양을 변경 하는 DataGridView합니다.To improve performance, set the properties in a DataGridViewCellPaintingEventArgs to change the appearance of the cell instead of directly accessing a cell in the DataGridView. 셀을 수동으로 그리는 경우에 설정 된 HandledEventArgs.Handled 속성을 true입니다.If you manually paint the cell, set the HandledEventArgs.Handled property to true. 설정 하지 않은 경우 HandledEventArgs.Handledtrue, 셀 사용자 지정 위에 그려집니다.If you do not set HandledEventArgs.Handled to true, the cell will paint over your customizations.

생성자

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

DataGridViewCellPaintingEventArgs 클래스의 새 인스턴스를 초기화합니다.Initializes a new instance of the DataGridViewCellPaintingEventArgs class.

속성

AdvancedBorderStyle AdvancedBorderStyle AdvancedBorderStyle AdvancedBorderStyle

현재 DataGridViewCell의 테두리 스타일을 가져옵니다.Gets the border style of the current DataGridViewCell.

CellBounds CellBounds CellBounds CellBounds

현재 DataGridViewCell의 범위를 가져옵니다.Get the bounds of the current DataGridViewCell.

CellStyle CellStyle CellStyle CellStyle

현재 DataGridViewCell의 셀 스타일을 가져옵니다.Gets the cell style of the current DataGridViewCell.

ClipBounds ClipBounds ClipBounds ClipBounds

다시 그려야 하는 DataGridView의 영역을 가져옵니다.Gets the area of the DataGridView that needs to be repainted.

ColumnIndex ColumnIndex ColumnIndex ColumnIndex

현재 DataGridViewCell의 열 인덱스를 가져옵니다.Gets the column index of the current DataGridViewCell.

ErrorText ErrorText ErrorText ErrorText

현재 DataGridViewCell에 대한 오류 메시지를 나타내는 문자열을 가져옵니다.Gets a string that represents an error message for the current DataGridViewCell.

FormattedValue FormattedValue FormattedValue FormattedValue

현재 DataGridViewCell의 서식이 지정된 값을 가져옵니다.Gets the formatted value of the current DataGridViewCell.

Graphics Graphics Graphics Graphics

현재 Graphics을 그리는 데 사용되는 DataGridViewCell를 가져옵니다.Gets the Graphics used to paint the current DataGridViewCell.

Handled Handled Handled Handled

이벤트 처리기에서 이벤트를 완전히 처리했는지 아니면 시스템에서 처리를 계속해야 하는지를 나타내는 값을 가져오거나 설정합니다.Gets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing.

(Inherited from HandledEventArgs)
PaintParts PaintParts PaintParts PaintParts

그릴 셀 부분입니다.The cell parts that are to be painted.

RowIndex RowIndex RowIndex RowIndex

현재 DataGridViewCell의 행 인덱스를 가져옵니다.Gets the row index of the current DataGridViewCell.

State State State State

현재 DataGridViewCell의 상태를 가져옵니다.Gets the state of the current DataGridViewCell.

Value Value Value Value

현재 DataGridViewCell의 값을 가져옵니다.Gets the value of the current DataGridViewCell.

메서드

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

지정한 개체와 현재 개체가 같은지 여부를 확인합니다.Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

기본 해시 함수로 작동합니다.Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

현재 인스턴스의 Type을 가져옵니다.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

현재 Object의 단순 복사본을 만듭니다.Creates a shallow copy of the current Object.

(Inherited from Object)
Paint(Rectangle, DataGridViewPaintParts) Paint(Rectangle, DataGridViewPaintParts) Paint(Rectangle, DataGridViewPaintParts) Paint(Rectangle, DataGridViewPaintParts)

지정된 범위의 영역에 지정된 셀 부분을 그립니다.Paints the specified parts of the cell for the area in the specified bounds.

PaintBackground(Rectangle, Boolean) PaintBackground(Rectangle, Boolean) PaintBackground(Rectangle, Boolean) PaintBackground(Rectangle, Boolean)

지정된 범위의 영역에 셀 배경을 그립니다.Paints the cell background for the area in the specified bounds.

PaintContent(Rectangle) PaintContent(Rectangle) PaintContent(Rectangle) PaintContent(Rectangle)

지정된 범위의 영역에 셀 내용을 그립니다.Paints the cell content for the area in the specified bounds.

ToString() ToString() ToString() ToString()

현재 개체를 나타내는 문자열을 반환합니다.Returns a string that represents the current object.

(Inherited from Object)

적용 대상

추가 정보