DataGridViewRowPrePaintEventArgs DataGridViewRowPrePaintEventArgs DataGridViewRowPrePaintEventArgs DataGridViewRowPrePaintEventArgs Class

定义

RowPrePaint 事件提供数据。Provides data for the RowPrePaint event.

public ref class DataGridViewRowPrePaintEventArgs : System::ComponentModel::HandledEventArgs
public class DataGridViewRowPrePaintEventArgs : System.ComponentModel.HandledEventArgs
type DataGridViewRowPrePaintEventArgs = class
    inherit HandledEventArgs
Public Class DataGridViewRowPrePaintEventArgs
Inherits HandledEventArgs
继承
DataGridViewRowPrePaintEventArgsDataGridViewRowPrePaintEventArgsDataGridViewRowPrePaintEventArgsDataGridViewRowPrePaintEventArgs

示例

下面的代码示例演示如何处理RowPrePaint事件以绘制选定单元格的自定义背景。The following code example demonstrates how to handle the RowPrePaint event to draw a custom background for selected cells. 此代码示例摘自如何:自定义 Windows 窗体 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 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 'dataGridView1_RowPrePaint

注解

RowPrePaint事件发生之前在绘制行DataGridView控件。The RowPrePaint event occurs before a row is painted on a DataGridView control. RowPrePaint 可将任何行中单元格绘制之前手动调整行的外观。RowPrePaint enables you to manually adjust the appearance of the row before any of the cells in the row are painted. 这是很有用,如果你想要自定义行,如生成其中某一列的内容所跨越多个列的行。This is useful if you want to customize the row, such as to produce a row where the content of one column spans multiple columns. 使用中的属性DataGridViewRowPrePaintEventArgs若要获取的行的设置,而无需直接访问中的行DataGridViewUse the properties in DataGridViewRowPrePaintEventArgs to get the settings of the row without directly accessing the row in the DataGridView.

构造函数

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

初始化 DataGridViewRowPrePaintEventArgs 类的新实例。Initializes a new instance of the DataGridViewRowPrePaintEventArgs class.

属性

ClipBounds ClipBounds ClipBounds ClipBounds

获取或设置需要重新绘制的 DataGridView 区域。Gets or sets the area of the DataGridView that needs to be repainted.

ErrorText ErrorText ErrorText ErrorText

获取表示当前 DataGridViewRow 的错误消息的字符串。Gets a string that represents an error message for the current DataGridViewRow.

Graphics Graphics Graphics Graphics

获取用于绘制当前 GraphicsDataGridViewRowGets the Graphics used to paint the current DataGridViewRow.

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

获取应用于行的单元格样式。Gets the cell style applied to the row.

IsFirstDisplayedRow IsFirstDisplayedRow IsFirstDisplayedRow IsFirstDisplayedRow

获取一个指示当前行是否为 DataGridView 中当前显示的第一行的值。Gets a value indicating whether the current row is the first row currently displayed in the DataGridView.

IsLastVisibleRow IsLastVisibleRow IsLastVisibleRow IsLastVisibleRow

获取一个指示当前行是否为 DataGridView 中最后一个可见行的值。Gets a value indicating whether the current row is the last visible row in the DataGridView.

PaintParts PaintParts PaintParts PaintParts

要绘制的单元格部分。The cell parts that are to be painted.

RowBounds RowBounds RowBounds RowBounds

获取当前 DataGridViewRow 的边界。Get the bounds of the current DataGridViewRow.

RowIndex RowIndex RowIndex RowIndex

获取当前 DataGridViewRow 的索引。Gets the index of the current DataGridViewRow.

State State State State

获取当前 DataGridViewRow 的状态。Gets the state of the current DataGridViewRow.

方法

DrawFocus(Rectangle, Boolean) DrawFocus(Rectangle, Boolean) DrawFocus(Rectangle, Boolean) DrawFocus(Rectangle, Boolean)

围绕指定的边界绘制聚焦框。Draws the focus rectangle around the specified bounds.

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

获取当前实例的 TypeGets 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)
PaintCells(Rectangle, DataGridViewPaintParts) PaintCells(Rectangle, DataGridViewPaintParts) PaintCells(Rectangle, DataGridViewPaintParts) PaintCells(Rectangle, DataGridViewPaintParts)

为指定边界中的区域绘制指定的单元格部分。Paints the specified cell parts for the area in the specified bounds.

PaintCellsBackground(Rectangle, Boolean) PaintCellsBackground(Rectangle, Boolean) PaintCellsBackground(Rectangle, Boolean) PaintCellsBackground(Rectangle, Boolean)

为指定边界中的区域绘制单元格背景。Paints the cell backgrounds for the area in the specified bounds.

PaintCellsContent(Rectangle) PaintCellsContent(Rectangle) PaintCellsContent(Rectangle) PaintCellsContent(Rectangle)

为指定边界中的区域绘制单元格内容。Paints the cell contents for the area in the specified bounds.

PaintHeader(Boolean) PaintHeader(Boolean) PaintHeader(Boolean) PaintHeader(Boolean)

绘制当前 DataGridViewRow 的整个行标头。Paints the entire row header of the current DataGridViewRow.

PaintHeader(DataGridViewPaintParts) PaintHeader(DataGridViewPaintParts) PaintHeader(DataGridViewPaintParts) PaintHeader(DataGridViewPaintParts)

绘制当前行的行标头的指定部分。Paints the specified parts of the row header of the current row.

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

返回表示当前对象的字符串。Returns a string that represents the current object.

(Inherited from Object)

适用于

另请参阅