DataGridViewRowPrePaintEventArgs 類別

定義

提供 RowPrePaint 事件的資料。

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

範例

下列程式碼範例示範如何處理 RowPrePaint 事件,以繪製所選儲存格的自訂背景。 此程式碼範例是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

備註

RowPrePaint 事件會在在控制項上 DataGridView 繪製資料列之前發生。 RowPrePaint 可讓您在繪製資料列中的任何儲存格之前,手動調整資料列的外觀。 如果您想要自訂資料列,例如產生一個資料行內容跨越多個資料行的資料列,這會很有用。 使用 中的 DataGridViewRowPrePaintEventArgs 屬性來取得資料列的設定,而不需要直接存取 中的資料 DataGridView 列。

建構函式

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

初始化 DataGridViewRowPrePaintEventArgs 類別的新執行個體。

屬性

ClipBounds

取得或設定需要重新繪製的 DataGridView 區域。

ErrorText

取得字串,表示目前 DataGridViewRow 的錯誤訊息。

Graphics

取得用來繪製目前 GraphicsDataGridViewRow

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)

適用於

另請參閱