DataGridView.RowPrePaint DataGridView.RowPrePaint DataGridView.RowPrePaint DataGridView.RowPrePaint Event

정의

DataGridViewRow가 칠해지기 전에 발생합니다.Occurs before a DataGridViewRow is painted

public:
 event System::Windows::Forms::DataGridViewRowPrePaintEventHandler ^ RowPrePaint;
public event System.Windows.Forms.DataGridViewRowPrePaintEventHandler RowPrePaint;
member this.RowPrePaint : System.Windows.Forms.DataGridViewRowPrePaintEventHandler 
Public Custom Event RowPrePaint As DataGridViewRowPrePaintEventHandler 

예제

다음 코드 예제에 대 한 처리기를 사용 하는 방법에 설명 합니다 RowPrePaint 이벤트 그라데이션 행 배경을 행을 선택한 경우.The following code example demonstrates how to use a handler for the RowPrePaint event to paint a gradient row background if the row is selected. 이 예제는에서 사용할 수 있는 보다 큰 예제의 일부 방법: Windows Forms DataGridView 컨트롤에서 행 모양 사용자 지정합니다.This example is part of a larger example available in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

// Paints the custom selection background for selected rows.
void dataGridView1_RowPrePaint(object sender,
        DataGridViewRowPrePaintEventArgs e)
{
    // Do not automatically paint the focus rectangle.
    e.PaintParts &= ~DataGridViewPaintParts.Focus;

    // Determine whether the cell should be painted
    // with the custom selection background.
    if ((e.State & DataGridViewElementStates.Selected) ==
                DataGridViewElementStates.Selected)
    {
        // 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);

        // Paint the custom selection background.
        using (Brush backbrush =
            new System.Drawing.Drawing2D.LinearGradientBrush(rowBounds,
                this.dataGridView1.DefaultCellStyle.SelectionBackColor,
                e.InheritedRowStyle.ForeColor,
                System.Drawing.Drawing2D.LinearGradientMode.Horizontal))
        {
            e.Graphics.FillRectangle(backbrush, rowBounds);
        }
    }
}
' Paints the custom selection background for selected rows.
Sub dataGridView1_RowPrePaint(ByVal sender As Object, _
    ByVal e As DataGridViewRowPrePaintEventArgs) _
    Handles dataGridView1.RowPrePaint

    ' Do not automatically paint the focus rectangle.
    e.PaintParts = e.PaintParts And Not DataGridViewPaintParts.Focus

    ' Determine whether the cell should be painted with the 
    ' custom selection background.
    If (e.State And DataGridViewElementStates.Selected) = _
        DataGridViewElementStates.Selected Then

        ' 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)

        ' Paint the custom selection background.
        Dim backbrush As New _
            System.Drawing.Drawing2D.LinearGradientBrush(rowBounds, _
            Me.dataGridView1.DefaultCellStyle.SelectionBackColor, _
            e.InheritedRowStyle.ForeColor, _
            System.Drawing.Drawing2D.LinearGradientMode.Horizontal)
        Try
            e.Graphics.FillRectangle(backbrush, rowBounds)
        Finally
            backbrush.Dispose()
        End Try
    End If

End Sub

설명

단독으로 또는 함께에서이 이벤트를 처리할 수 있습니다는 RowPostPaint 컨트롤에서 행의 모양을 사용자 지정 하는 이벤트입니다.You can handle this event alone or in combination with the RowPostPaint event to customize the appearance of rows in the control. 사용자가 직접 또는 행의 특정 부분 행 전체를 그릴 수 있으며의 다음 메서드를 사용 합니다 DataGridViewRowPrePaintEventArgs 다른 부분을 그릴 클래스:You can paint entire rows yourself, or paint specific parts of rows and use the following methods of the DataGridViewRowPrePaintEventArgs class to paint other parts:

사용할 수도 있습니다는 VisualStyleRenderer 현재 테마를 사용 하 여 표준 컨트롤을 그릴 클래스입니다.You can also use the VisualStyleRenderer class to paint standard controls using the current theme. 자세한 내용은 비주얼 스타일을 사용 하 여 컨트롤 렌더링합니다.For more information, see Rendering Controls with Visual Styles. 사용 중인 경우 Visual Studio 2005Visual Studio 2005를 사용 하 여 사용할 수 있는 표준 이미지의 대규모 라이브러리에 액세스할 수도 DataGridView 제어 합니다.If you are using Visual Studio 2005Visual Studio 2005, you also have access to a large library of standard images that you can use with the DataGridView control.

이벤트를 처리 하는 방법에 대 한 자세한 내용은 참조 하세요. 이벤트 처리 및 발생합니다.For more information about how to handle events, see Handling and Raising Events.

적용 대상

추가 정보