DataGridView.RowPostPaint イベント
アセンブリ: System.Windows.Forms (system.windows.forms.dll 内)

Dim instance As DataGridView Dim handler As DataGridViewRowPostPaintEventHandler AddHandler instance.RowPostPaint, handler
public: event DataGridViewRowPostPaintEventHandler^ RowPostPaint { void add (DataGridViewRowPostPaintEventHandler^ value); void remove (DataGridViewRowPostPaintEventHandler^ value); }

このイベントは単独で処理することもできますが、RowPrePaint イベントと組み合わせて処理することで、コントロールの行の外観をカスタマイズできます。セル全体を独自に描画したり、行の一部分だけを描画したりできるほか、DataGridViewRowPostPaintEventArgs クラスの次のメソッドを使用して、その他の部分を描画することもできます。
-
DrawFocus
-
PaintCells
-
PaintCellsBackground
-
PaintCellsContent
-
PaintHeader
また、VisualStyleRenderer クラスを使用することにより、現在のテーマを使って標準コントロールを描画することもできます。詳細については、「visual スタイルが使用されているコントロールのレンダリング」を参照してください。Visual Studio 2005 を使用している場合は、豊富な標準イメージ ライブラリにアクセスし、DataGridView コントロールと組み合わせて使用することもできます。

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); } }

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


DataGridView クラス
DataGridView メンバ
System.Windows.Forms 名前空間
その他の技術情報
DataGridView コントロール (Windows フォーム)
Weblioに収録されているすべての辞書からDataGridView.RowPostPaint イベントを検索する場合は、下記のリンクをクリックしてください。

- DataGridView.RowPostPaint イベントのページへのリンク