DataGridViewRowPrePaintEventArgs 类       
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
为 RowPrePaint 事件提供数据。
public ref class DataGridViewRowPrePaintEventArgs : System::ComponentModel::HandledEventArgspublic class DataGridViewRowPrePaintEventArgs : System.ComponentModel.HandledEventArgstype DataGridViewRowPrePaintEventArgs = class
    inherit HandledEventArgsPublic Class DataGridViewRowPrePaintEventArgs
Inherits HandledEventArgs- 继承
示例
下面的代码示例演示如何处理 事件, RowPrePaint 为所选单元格绘制自定义背景。 此代码示例是 How to: Customize the Appearance of Rows in the Windows 窗体 DataGridView 控件中提供的更大示例的一部分。
// 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
注解
在 RowPrePaint 控件上 DataGridView 绘制行之前发生该事件。 RowPrePaint 使你能够在绘制行中的任何单元格之前手动调整行的外观。 如果要自定义行,例如生成一列内容跨多个列的行,这非常有用。 使用 中的 DataGridViewRowPrePaintEventArgs 属性获取行的设置,而无需直接访问 中的 DataGridView行。
构造函数
属性
| ClipBounds | 获取或设置需要重新绘制的 DataGridView 区域。 | 
| ErrorText | 获取表示当前 DataGridViewRow 的错误消息的字符串。 | 
| Graphics | 获取用于绘制当前 Graphics 的 DataGridViewRow。 | 
| Handled | 获取或设置一个值,该值指示事件处理程序是否已完整处理事件,或者系统是否应该继续本身的处理。(继承自 HandledEventArgs) | 
| InheritedRowStyle | 获取应用于行的单元格样式。 | 
| IsFirstDisplayedRow | 获取一个指示当前行是否为 DataGridView 中当前显示的第一行的值。 | 
| IsLastVisibleRow | 获取一个指示当前行是否为 DataGridView 中最后一个可见行的值。 | 
| PaintParts | 要绘制的单元格部分。 | 
| RowBounds | 获取当前 DataGridViewRow 的边界。 | 
| RowIndex | 获取当前 DataGridViewRow 的索引。 | 
| State | 获取当前 DataGridViewRow 的状态。 | 
方法
| DrawFocus(Rectangle, Boolean) | 围绕指定的边界绘制聚焦框。 | 
| Equals(Object) | 确定指定对象是否等于当前对象。(继承自 Object) | 
| GetHashCode() | 作为默认哈希函数。(继承自 Object) | 
| GetType() | 获取当前实例的 Type。(继承自 Object) | 
| MemberwiseClone() | 创建当前 Object 的浅表副本。(继承自 Object) | 
| PaintCells(Rectangle, DataGridViewPaintParts) | 为指定边界中的区域绘制指定的单元格部分。 | 
| PaintCellsBackground(Rectangle, Boolean) | 为指定边界中的区域绘制单元格背景。 | 
| PaintCellsContent(Rectangle) | 为指定边界中的区域绘制单元格内容。 | 
| PaintHeader(Boolean) | 绘制当前 DataGridViewRow 的整个行标头。 | 
| PaintHeader(DataGridViewPaintParts) | 绘制当前行的行标头的指定部分。 | 
| ToString() | 返回表示当前对象的字符串。(继承自 Object) |