DataGridViewRowPostPaintEventArgsとは? わかりやすく解説

Weblio 辞書 > コンピュータ > .NET Framework クラス ライブラリ リファレンス > DataGridViewRowPostPaintEventArgsの意味・解説 

DataGridViewRowPostPaintEventArgs クラス

メモ : このクラスは、.NET Framework version 2.0 で新しく追加されたものです。

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

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Class DataGridViewRowPostPaintEventArgs
    Inherits EventArgs
Dim instance As DataGridViewRowPostPaintEventArgs
public class DataGridViewRowPostPaintEventArgs
 : EventArgs
public ref class DataGridViewRowPostPaintEventArgs
 : public EventArgs
public class DataGridViewRowPostPaintEventArgs
 extends EventArgs
public class DataGridViewRowPostPaintEventArgs
 extends EventArgs
解説解説

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

使用例使用例

RowPostPaint イベントを処理して、セルの内容が行全体にわたるようにするコード例を次に示します。次のコード例は、「方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズする」で示されている例の一部です。

' 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 Not (recipe Is
 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 'dataGridView1_RowPostPaint
// 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);
    }
}
継承階層継承階層
System.Object
   System.EventArgs
    System.Windows.Forms.DataGridViewRowPostPaintEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

DataGridViewRowPostPaintEventArgs コンストラクタ

メモ : このコンストラクタは、.NET Framework version 2.0 で新しく追加されたものです。

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

名前空間: System.Windows.Forms
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)
構文構文

Public Sub New ( _
    dataGridView As DataGridView, _
    graphics As Graphics, _
    clipBounds As Rectangle, _
    rowBounds As Rectangle, _
    rowIndex As Integer, _
    rowState As DataGridViewElementStates, _
    errorText As String, _
    inheritedRowStyle As DataGridViewCellStyle, _
    isFirstDisplayedRow As Boolean, _
    isLastVisibleRow As Boolean _
)
Dim dataGridView As DataGridView
Dim graphics As Graphics
Dim clipBounds As Rectangle
Dim rowBounds As Rectangle
Dim rowIndex As Integer
Dim rowState As DataGridViewElementStates
Dim errorText As String
Dim inheritedRowStyle As DataGridViewCellStyle
Dim isFirstDisplayedRow As Boolean
Dim isLastVisibleRow As Boolean

Dim instance As New DataGridViewRowPostPaintEventArgs(dataGridView,
 graphics, clipBounds, rowBounds, rowIndex, rowState, errorText, inheritedRowStyle,
 isFirstDisplayedRow, isLastVisibleRow)
public DataGridViewRowPostPaintEventArgs (
    DataGridView dataGridView,
    Graphics graphics,
    Rectangle clipBounds,
    Rectangle rowBounds,
    int rowIndex,
    DataGridViewElementStates rowState,
    string errorText,
    DataGridViewCellStyle inheritedRowStyle,
    bool isFirstDisplayedRow,
    bool isLastVisibleRow
)
public:
DataGridViewRowPostPaintEventArgs (
    DataGridView^ dataGridView, 
    Graphics^ graphics, 
    Rectangle clipBounds, 
    Rectangle rowBounds, 
    int rowIndex, 
    DataGridViewElementStates rowState, 
    String^ errorText, 
    DataGridViewCellStyle^ inheritedRowStyle, 
    bool isFirstDisplayedRow, 
    bool isLastVisibleRow
)
public DataGridViewRowPostPaintEventArgs (
    DataGridView dataGridView, 
    Graphics graphics, 
    Rectangle clipBounds, 
    Rectangle rowBounds, 
    int rowIndex, 
    DataGridViewElementStates rowState, 
    String errorText, 
    DataGridViewCellStyle inheritedRowStyle, 
    boolean isFirstDisplayedRow, 
    boolean isLastVisibleRow
)
public function DataGridViewRowPostPaintEventArgs
 (
    dataGridView : DataGridView, 
    graphics : Graphics, 
    clipBounds : Rectangle, 
    rowBounds : Rectangle, 
    rowIndex : int, 
    rowState : DataGridViewElementStates, 
    errorText : String, 
    inheritedRowStyle : DataGridViewCellStyle, 
    isFirstDisplayedRow : boolean, 
    isLastVisibleRow : boolean
)

パラメータ

dataGridView

描画される行を所有する DataGridView。

graphics

DataGridViewRow の描画に使用する Graphics。

clipBounds

描画が必要な DataGridView の領域を表す Rectangle。

rowBounds

描画される DataGridViewRow の境界が格納された Rectangle。

rowIndex

描画されるセルの行インデックス。

rowState

行の状態を指定する DataGridViewElementStates 値のビットごとの組み合わせ。

errorText

行に関連付けられたエラー メッセージ。

inheritedRowStyle

行に関する書式とスタイルの情報が格納された DataGridViewCellStyle。

isFirstDisplayedRow

現在の行が、現在 DataGridView に表示されている最初の行かどうかを示す場合は true。それ以外の場合は false。

isLastVisibleRow

現在の行が、Visible プロパティが true に設定された、DataGridView の最後の行かどうかを示す場合は true。それ以外の場合は false。

例外例外
例外の種類条件

ArgumentNullException

dataGridView が null 参照 (Visual Basic では Nothing) です。

または

graphics が null 参照 (Visual Basic では Nothing) です。

または

inheritedRowStyle が null 参照 (Visual Basic では Nothing) です。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridViewRowPostPaintEventArgs クラス
DataGridViewRowPostPaintEventArgs メンバ
System.Windows.Forms 名前空間
DataGridView クラス
Graphics
Rectangle
DataGridViewRow クラス
DataGridViewElementStates 列挙体
DataGridViewCellStyle クラス

DataGridViewRowPostPaintEventArgs プロパティ


パブリック プロパティパブリック プロパティ

  名前 説明
パブリック プロパティ ClipBounds 再描画が必要な DataGridView の領域を取得または設定します。
パブリック プロパティ ErrorText 現在の DataGridViewRow のエラー メッセージを表す文字列を取得します。
パブリック プロパティ Graphics 現在の DataGridViewRow の描画に使用される Graphics を取得します。
パブリック プロパティ InheritedRowStyle 現在の DataGridViewRow に適用されるセル スタイルを取得します。
パブリック プロパティ IsFirstDisplayedRow 現在の行が DataGridView に表示される最初の行かどうかを示す値を取得します。
パブリック プロパティ IsLastVisibleRow 現在の行が DataGridView に表示される最後の行かどうかを示す値を取得します。
パブリック プロパティ RowBounds 現在の DataGridViewRow の境界を取得します。
パブリック プロパティ RowIndex 現在の DataGridViewRow のインデックスを取得します。
パブリック プロパティ State 現在の DataGridViewRow の状態を取得します。
参照参照

関連項目

DataGridViewRowPostPaintEventArgs クラス
System.Windows.Forms 名前空間
DataGridView クラス

その他の技術情報

方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズする

DataGridViewRowPostPaintEventArgs メソッド


パブリック メソッドパブリック メソッド

プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DataGridViewRowPostPaintEventArgs クラス
System.Windows.Forms 名前空間
DataGridView クラス

その他の技術情報

方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズする

DataGridViewRowPostPaintEventArgs メンバ

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

DataGridViewRowPostPaintEventArgs データ型で公開されるメンバを以下の表に示します。


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド DataGridViewRowPostPaintEventArgs DataGridViewRowPostPaintEventArgs クラスの新しいインスタンスを初期化します。
パブリック プロパティパブリック プロパティ
  名前 説明
パブリック プロパティ ClipBounds 再描画が必要な DataGridView の領域を取得または設定します。
パブリック プロパティ ErrorText 現在の DataGridViewRow のエラー メッセージを表す文字列を取得します。
パブリック プロパティ Graphics 現在の DataGridViewRow の描画に使用される Graphics を取得します。
パブリック プロパティ InheritedRowStyle 現在の DataGridViewRow に適用されるセル スタイルを取得します。
パブリック プロパティ IsFirstDisplayedRow 現在の行が DataGridView に表示される最初の行かどうかを示す値を取得します。
パブリック プロパティ IsLastVisibleRow 現在の行が DataGridView に表示される最後の行かどうかを示す値を取得します。
パブリック プロパティ RowBounds 現在の DataGridViewRow の境界を取得します。
パブリック プロパティ RowIndex 現在の DataGridViewRow のインデックスを取得します。
パブリック プロパティ State 現在の DataGridViewRow の状態を取得します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DataGridViewRowPostPaintEventArgs クラス
System.Windows.Forms 名前空間
DataGridView クラス

その他の技術情報

方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズする



英和和英テキスト翻訳

英語⇒日本語日本語⇒英語

辞書ショートカット

すべての辞書の索引

「DataGridViewRowPostPaintEventArgs」の関連用語

DataGridViewRowPostPaintEventArgsのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



DataGridViewRowPostPaintEventArgsのページの著作権

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2026 Microsoft.All rights reserved.

©2026 GRAS Group, Inc.RSS