DataGridViewRowPostPaintEventArgs クラス
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)


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.EventArgs
System.Windows.Forms.DataGridViewRowPostPaintEventArgs


Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridViewRowPostPaintEventArgs コンストラクタ
アセンブリ: 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 )

例外の種類 | 条件 |
---|---|
ArgumentNullException | dataGridView が null 参照 (Visual Basic では Nothing) です。 または graphics が null 参照 (Visual Basic では Nothing) です。 または inheritedRowStyle が null 参照 (Visual Basic では Nothing) です。 |

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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 メソッド

名前 | 説明 | |
---|---|---|
![]() | DrawFocus | 指定した境界の周囲にフォーカスを表す四角形を描画します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 ( Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 ( Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 ( Object から継承されます。) |
![]() | PaintCells | 指定した境界内の領域に対応する指定したセルの部分を描画します。 |
![]() | PaintCellsBackground | 指定した境界内の領域に対応するセルの背景を描画します。 |
![]() | PaintCellsContent | 指定した境界内の領域に対応するセルの内容を描画します。 |
![]() | PaintHeader | オーバーロードされます。 現在の行の行ヘッダーを描画します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 ( Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 ( Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 ( Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 ( Object から継承されます。) |

関連項目
DataGridViewRowPostPaintEventArgs クラスSystem.Windows.Forms 名前空間
DataGridView クラス
その他の技術情報
方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズするDataGridViewRowPostPaintEventArgs メンバ
DataGridViewRowPostPaintEventArgs データ型で公開されるメンバを以下の表に示します。


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

名前 | 説明 | |
---|---|---|
![]() | DrawFocus | 指定した境界の周囲にフォーカスを表す四角形を描画します。 |
![]() | Equals | オーバーロードされます。 2 つの Object インスタンスが等しいかどうかを判断します。 (Object から継承されます。) |
![]() | GetHashCode | 特定の型のハッシュ関数として機能します。GetHashCode は、ハッシュ アルゴリズムや、ハッシュ テーブルのようなデータ構造での使用に適しています。 (Object から継承されます。) |
![]() | GetType | 現在のインスタンスの Type を取得します。 (Object から継承されます。) |
![]() | PaintCells | 指定した境界内の領域に対応する指定したセルの部分を描画します。 |
![]() | PaintCellsBackground | 指定した境界内の領域に対応するセルの背景を描画します。 |
![]() | PaintCellsContent | 指定した境界内の領域に対応するセルの内容を描画します。 |
![]() | PaintHeader | オーバーロードされます。 現在の行の行ヘッダーを描画します。 |
![]() | ReferenceEquals | 指定した複数の Object インスタンスが同一かどうかを判断します。 (Object から継承されます。) |
![]() | ToString | 現在の Object を表す String を返します。 (Object から継承されます。) |

名前 | 説明 | |
---|---|---|
![]() | Finalize | Object がガベージ コレクションにより収集される前に、その Object がリソースを解放し、その他のクリーンアップ操作を実行できるようにします。 (Object から継承されます。) |
![]() | MemberwiseClone | 現在の Object の簡易コピーを作成します。 (Object から継承されます。) |

関連項目
DataGridViewRowPostPaintEventArgs クラスSystem.Windows.Forms 名前空間
DataGridView クラス
その他の技術情報
方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズするWeblioに収録されているすべての辞書からDataGridViewRowPostPaintEventArgsを検索する場合は、下記のリンクをクリックしてください。

- DataGridViewRowPostPaintEventArgsのページへのリンク