DataGridViewRowPostPaintEventArgs DataGridViewRowPostPaintEventArgs DataGridViewRowPostPaintEventArgs DataGridViewRowPostPaintEventArgs Class

定義

RowPostPaint イベントのデータを提供します。Provides data for the RowPostPaint event.

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

次のコード例では、 RowPostPaintイベントを処理して、セルの内容が行全体にまたがるようにする方法を示します。The following code example demonstrates how to handle the RowPostPaint event to make the content of a cell span the entire row. このコード例は、次の方法で提供される大規模な例の一部です。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 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コントロールに行が描画された後に発生します。The RowPostPaint event occurs after a row is painted on a DataGridView control. RowPostPaint行内のセルを描画した後に、行の外観を手動で調整できます。RowPostPaint allows you to manually adjust the appearance of the row after the cells in the row are painted. これは、行をカスタマイズする場合に便利です。This is useful if you want to customize the row.

コンストラクター

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

DataGridViewRowPostPaintEventArgs クラスの新しいインスタンスを初期化します。Initializes a new instance of the DataGridViewRowPostPaintEventArgs 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

現在の Graphics の描画に使用される DataGridViewRow を取得します。Gets the Graphics used to paint the current DataGridViewRow.

InheritedRowStyle InheritedRowStyle InheritedRowStyle InheritedRowStyle

現在の DataGridViewRow に適用されるセル スタイルを取得します。Gets the cell style applied to the current DataGridViewRow.

IsFirstDisplayedRow IsFirstDisplayedRow IsFirstDisplayedRow IsFirstDisplayedRow

現在の行が DataGridView に表示される最初の行かどうかを示す値を取得します。Gets a value indicating whether the current row is the first row displayed in the DataGridView.

IsLastVisibleRow IsLastVisibleRow IsLastVisibleRow IsLastVisibleRow

現在の行が DataGridView に表示される最後の行かどうかを示す値を取得します。Gets a value indicating whether the current row is the last visible row displayed in the DataGridView.

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

現在のインスタンスの Type を取得します。Gets 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)

適用対象

こちらもご覧ください