DataGridViewRowPostPaintEventArgs クラス

定義

RowPostPaint イベントのデータを提供します。

public ref class DataGridViewRowPostPaintEventArgs : EventArgs
public class DataGridViewRowPostPaintEventArgs : EventArgs
type DataGridViewRowPostPaintEventArgs = class
    inherit EventArgs
Public Class DataGridViewRowPostPaintEventArgs
Inherits EventArgs
継承
DataGridViewRowPostPaintEventArgs

次のコード例では、 イベントを処理 RowPostPaint してセルの内容を行全体に広める方法を示します。 このコード例は、「方法: Windows フォーム DataGridView コントロールの行の外観をカスタマイズする」で提供されるより大きな例の一部です。

// Paints the content that spans multiple columns and the focus rectangle.
void dataGridView1_RowPostPaint(object sender,
    DataGridViewRowPostPaintEventArgs e)
{
    // 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);

    SolidBrush forebrush = null;
    try
    {
        // Determine the foreground color.
        if ((e.State & DataGridViewElementStates.Selected) ==
            DataGridViewElementStates.Selected)
        {
            forebrush = new SolidBrush(e.InheritedRowStyle.SelectionForeColor);
        }
        else
        {
            forebrush = new SolidBrush(e.InheritedRowStyle.ForeColor);
        }

        // Get the content that spans multiple columns.
        object recipe =
            this.dataGridView1.Rows.SharedRow(e.RowIndex).Cells[2].Value;

        if (recipe != null)
        {
            String text = recipe.ToString();

            // Calculate the bounds for the content that spans multiple 
            // columns, adjusting for the horizontal scrolling position 
            // and the current row height, and displaying only whole
            // lines of text.
            Rectangle textArea = rowBounds;
            textArea.X -= this.dataGridView1.HorizontalScrollingOffset;
            textArea.Width += this.dataGridView1.HorizontalScrollingOffset;
            textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom;
            textArea.Height -= rowBounds.Height -
                e.InheritedRowStyle.Padding.Bottom;
            textArea.Height = (textArea.Height / e.InheritedRowStyle.Font.Height) *
                e.InheritedRowStyle.Font.Height;

            // Calculate the portion of the text area that needs painting.
            RectangleF clip = textArea;
            clip.Width -= this.dataGridView1.RowHeadersWidth + 1 - clip.X;
            clip.X = this.dataGridView1.RowHeadersWidth + 1;
            RectangleF oldClip = e.Graphics.ClipBounds;
            e.Graphics.SetClip(clip);

            // Draw the content that spans multiple columns.
            e.Graphics.DrawString(
                text, e.InheritedRowStyle.Font, forebrush, textArea);

            e.Graphics.SetClip(oldClip);
        }
    }
    finally
    {
        forebrush.Dispose();
    }

    if (this.dataGridView1.CurrentCellAddress.Y == e.RowIndex)
    {
        // Paint the focus rectangle.
        e.DrawFocus(rowBounds, true);
    }
}
' Paints the content that spans multiple columns and the focus rectangle.
Sub dataGridView1_RowPostPaint(ByVal sender As Object, _
    ByVal e As DataGridViewRowPostPaintEventArgs) _
    Handles dataGridView1.RowPostPaint

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

    Dim forebrush As SolidBrush = Nothing
    Try
        ' Determine the foreground color.
        If (e.State And DataGridViewElementStates.Selected) = _
            DataGridViewElementStates.Selected Then

            forebrush = New SolidBrush(e.InheritedRowStyle.SelectionForeColor)
        Else
            forebrush = New SolidBrush(e.InheritedRowStyle.ForeColor)
        End If

        ' Get the content that spans multiple columns.
        Dim recipe As Object = _
            Me.dataGridView1.Rows.SharedRow(e.RowIndex).Cells(2).Value

        If (recipe IsNot Nothing) Then
            Dim text As String = recipe.ToString()

            ' Calculate the bounds for the content that spans multiple 
            ' columns, adjusting for the horizontal scrolling position 
            ' and the current row height, and displaying only whole
            ' lines of text.
            Dim textArea As Rectangle = rowBounds
            textArea.X -= Me.dataGridView1.HorizontalScrollingOffset
            textArea.Width += Me.dataGridView1.HorizontalScrollingOffset
            textArea.Y += rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
            textArea.Height -= rowBounds.Height - e.InheritedRowStyle.Padding.Bottom
            textArea.Height = (textArea.Height \ e.InheritedRowStyle.Font.Height) * _
                e.InheritedRowStyle.Font.Height

            ' Calculate the portion of the text area that needs painting.
            Dim clip As RectangleF = textArea
            clip.Width -= Me.dataGridView1.RowHeadersWidth + 1 - clip.X
            clip.X = Me.dataGridView1.RowHeadersWidth + 1
            Dim oldClip As RectangleF = e.Graphics.ClipBounds
            e.Graphics.SetClip(clip)

            ' Draw the content that spans multiple columns.
            e.Graphics.DrawString(text, e.InheritedRowStyle.Font, forebrush, _
                textArea)

            e.Graphics.SetClip(oldClip)
        End If
    Finally
        forebrush.Dispose()
    End Try

    If Me.dataGridView1.CurrentCellAddress.Y = e.RowIndex Then
        ' Paint the focus rectangle.
        e.DrawFocus(rowBounds, True)
    End If

End Sub

注釈

イベントは RowPostPaint 、コントロールに行が描画された後に DataGridView 発生します。 RowPostPaint では、行内のセルを塗りつぶした後に、行の外観を手動で調整できます。 これは、行をカスタマイズする場合に便利です。

コンストラクター

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

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

プロパティ

ClipBounds

再描画が必要な DataGridView の領域を取得または設定します。

ErrorText

現在の DataGridViewRow のエラー メッセージを表す文字列を取得します。

Graphics

現在の Graphics の描画に使用される DataGridViewRow を取得します。

InheritedRowStyle

現在の DataGridViewRow に適用されるセル スタイルを取得します。

IsFirstDisplayedRow

現在の行が DataGridView に表示される最初の行かどうかを示す値を取得します。

IsLastVisibleRow

現在の行が DataGridView に表示される最後の行かどうかを示す値を取得します。

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)

適用対象

こちらもご覧ください