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 カスタム背景を描画する方法を示します。 このコード例は、「方法: 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 を使用すると、行内のセルが塗りつぶされる前に、行の外観を手動で調整できます。 これは、1 つの列の内容が複数の列にまたがる行を生成するなど、行をカスタマイズする場合に便利です。 内 DataGridViewRowPrePaintEventArgs の行に直接アクセスせずに行の設定を取得するには、 の プロパティを使用します DataGridView

コンストラクター

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

DataGridViewRowPrePaintEventArgs クラスの新しいインスタンスを初期化します。

プロパティ

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)

適用対象

こちらもご覧ください