DataGridViewRowPostPaintEventArgs 클래스

정의

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

public ref class DataGridViewRowPostPaintEventArgs : EventArgs
public class DataGridViewRowPostPaintEventArgs : EventArgs
type DataGridViewRowPostPaintEventArgs = class
    inherit EventArgs
Public Class DataGridViewRowPostPaintEventArgs
Inherits EventArgs
상속
DataGridViewRowPostPaintEventArgs

예제

다음 코드 예제에서는 처리 하는 방법에 설명 합니다 RowPostPaint 전체 행을 셀의 내용을 확인 하는 이벤트입니다.The following code example demonstrates how to handle the RowPostPaint event to make the content of a cell span the entire row. 이 코드 예제는에서 제공 하는 더 큰 예제의 일부입니다 방법: Windows Forms DataGridView 컨트롤에서 행 모양 사용자 지정합니다.This code example is part of a larger example provided in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

// Paints the content that spans multiple columns and the focus rectangle.
void dataGridView1_RowPostPaint(object sender,
    DataGridViewRowPostPaintEventArgs e)
{
    // Calculate the bounds of the row.
    Rectangle rowBounds = new Rectangle(
        this.dataGridView1.RowHeadersWidth, e.RowBounds.Top,
        this.dataGridView1.Columns.GetColumnsWidth(
            DataGridViewElementStates.Visible) -
        this.dataGridView1.HorizontalScrollingOffset + 1,
        e.RowBounds.Height);

    SolidBrush forebrush = null;
    try
    {
        // Determine the foreground color.
        if ((e.State & DataGridViewElementStates.Selected) ==
            DataGridViewElementStates.Selected)
        {
            forebrush = new SolidBrush(e.InheritedRowStyle.SelectionForeColor);
        }
        else
        {
            forebrush = new SolidBrush(e.InheritedRowStyle.ForeColor);
        }

        // Get the content that spans multiple columns.
        object recipe =
            this.dataGridView1.Rows.SharedRow(e.RowIndex).Cells[2].Value;

        if (recipe != null)
        {
            String text = recipe.ToString();

            // Calculate the bounds for the content that spans multiple 
            // columns, adjusting for the horizontal scrolling position 
            // and the current row height, and displaying only whole
            // lines of text.
            Rectangle textArea = rowBounds;
            textArea.X -= this.dataGridView1.HorizontalScrollingOffset;
            textArea.Width += this.dataGridView1.HorizontalScrollingOffset;
            textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom;
            textArea.Height -= rowBounds.Height -
                e.InheritedRowStyle.Padding.Bottom;
            textArea.Height = (textArea.Height / e.InheritedRowStyle.Font.Height) *
                e.InheritedRowStyle.Font.Height;

            // Calculate the portion of the text area that needs painting.
            RectangleF clip = textArea;
            clip.Width -= this.dataGridView1.RowHeadersWidth + 1 - clip.X;
            clip.X = this.dataGridView1.RowHeadersWidth + 1;
            RectangleF oldClip = e.Graphics.ClipBounds;
            e.Graphics.SetClip(clip);

            // Draw the content that spans multiple columns.
            e.Graphics.DrawString(
                text, e.InheritedRowStyle.Font, forebrush, textArea);

            e.Graphics.SetClip(oldClip);
        }
    }
    finally
    {
        forebrush.Dispose();
    }

    if (this.dataGridView1.CurrentCellAddress.Y == e.RowIndex)
    {
        // Paint the focus rectangle.
        e.DrawFocus(rowBounds, true);
    }
}
' Paints the content that spans multiple columns and the focus rectangle.
Sub dataGridView1_RowPostPaint(ByVal sender As Object, _
    ByVal e As DataGridViewRowPostPaintEventArgs) _
    Handles dataGridView1.RowPostPaint

    ' Calculate the bounds of the row.
    Dim rowBounds As New Rectangle(Me.dataGridView1.RowHeadersWidth, _
        e.RowBounds.Top, Me.dataGridView1.Columns.GetColumnsWidth( _
        DataGridViewElementStates.Visible) - _
        Me.dataGridView1.HorizontalScrollingOffset + 1, e.RowBounds.Height)

    Dim forebrush As SolidBrush = Nothing
    Try
        ' Determine the foreground color.
        If (e.State And DataGridViewElementStates.Selected) = _
            DataGridViewElementStates.Selected Then

            forebrush = New SolidBrush(e.InheritedRowStyle.SelectionForeColor)
        Else
            forebrush = New SolidBrush(e.InheritedRowStyle.ForeColor)
        End If

        ' Get the content that spans multiple columns.
        Dim recipe As Object = _
            Me.dataGridView1.Rows.SharedRow(e.RowIndex).Cells(2).Value

        If (recipe IsNot Nothing) Then
            Dim text As String = recipe.ToString()

            ' Calculate the bounds for the content that spans multiple 
            ' columns, adjusting for the horizontal scrolling position 
            ' and the current row height, and displaying only whole
            ' lines of text.
            Dim textArea As Rectangle = rowBounds
            textArea.X -= Me.dataGridView1.HorizontalScrollingOffset
            textArea.Width += Me.dataGridView1.HorizontalScrollingOffset
            textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
            textArea.Height -= rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
            textArea.Height = (textArea.Height \ e.InheritedRowStyle.Font.Height) * _
                e.InheritedRowStyle.Font.Height

            ' Calculate the portion of the text area that needs painting.
            Dim clip As RectangleF = textArea
            clip.Width -= Me.dataGridView1.RowHeadersWidth + 1 - clip.X
            clip.X = Me.dataGridView1.RowHeadersWidth + 1
            Dim oldClip As RectangleF = e.Graphics.ClipBounds
            e.Graphics.SetClip(clip)

            ' Draw the content that spans multiple columns.
            e.Graphics.DrawString(text, e.InheritedRowStyle.Font, forebrush, _
                textArea)

            e.Graphics.SetClip(oldClip)
        End If
    Finally
        forebrush.Dispose()
    End Try

    If Me.dataGridView1.CurrentCellAddress.Y = e.RowIndex Then
        ' Paint the focus rectangle.
        e.DrawFocus(rowBounds, True)
    End If

End Sub

설명

RowPostPaint 이벤트에는 행을 그린 후에 발생 한 DataGridView 컨트롤입니다.The RowPostPaint event occurs after a row is painted on a DataGridView control. RowPostPaint 행의 셀이 그려진 후 행의 모양을 수동으로 조정할 수 있습니다.RowPostPaint allows you to manually adjust the appearance of the row after the cells in the row are painted. 행을 사용자 지정 하려는 경우에 유용 합니다.This is useful if you want to customize the row.

생성자

DataGridViewRowPostPaintEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, String, DataGridViewCellStyle, Boolean, Boolean)

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

속성

ClipBounds

다시 그려야 하는 DataGridView의 영역을 가져오거나 설정합니다.Gets or sets the area of the DataGridView that needs to be repainted.

ErrorText

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

Graphics

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

InheritedRowStyle

현재 DataGridViewRow에 적용된 셀 스타일을 가져옵니다.Gets the cell style applied to the current DataGridViewRow.

IsFirstDisplayedRow

현재 행이 DataGridView에 표시되는 첫 번째 행인지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether the current row is the first row displayed in the DataGridView.

IsLastVisibleRow

현재 행이 DataGridView에 표시되는 마지막 행인지 여부를 나타내는 값을 가져옵니다.Gets a value indicating whether the current row is the last visible row displayed in the DataGridView.

RowBounds

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

RowIndex

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

State

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

메서드

DrawFocus(Rectangle, Boolean)

지정된 범위 주위에 포커스 영역을 그립니다.Draws the focus rectangle around the specified bounds.

Equals(Object)

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

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

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

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

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

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

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

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

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

PaintCellsBackground(Rectangle, Boolean)

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

PaintCellsContent(Rectangle)

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

PaintHeader(Boolean)

현재 DataGridViewRow의 전체 행 머리글을 그립니다.Paints the entire row header of the current DataGridViewRow.

PaintHeader(DataGridViewPaintParts)

현재 행에 대한 행 머리글의 지정된 부분을 그립니다.Paints the specified parts of the row header of the current row.

ToString()

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

(다음에서 상속됨 Object)

적용 대상

추가 정보