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

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

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

RowPrePaint イベントのハンドラを使用して、行が選択されたときに、その行の背景をグラデーションで描画するコード例を次に示します。次の例は「方法 : Windows フォームの DataGridView コントロールの行の外観をカスタマイズする」で取り上げている例の一部です。
' Paints the custom selection background for selected rows. Sub dataGridView1_RowPrePaint(ByVal sender As Object, _ ByVal e As DataGridViewRowPrePaintEventArgs) _ Handles dataGridView1.RowPrePaint ' Do not automatically paint the focus rectangle. e.PaintParts = e.PaintParts And Not DataGridViewPaintParts.Focus ' Determine whether the cell should be painted with the ' custom selection background. If (e.State And DataGridViewElementStates.Selected) = _ DataGridViewElementStates.Selected Then ' 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) ' Paint the custom selection background. Dim backbrush As New _ System.Drawing.Drawing2D.LinearGradientBrush(rowBounds, _ Me.dataGridView1.DefaultCellStyle.SelectionBackColor, _ e.InheritedRowStyle.ForeColor, _ System.Drawing.Drawing2D.LinearGradientMode.Horizontal) Try e.Graphics.FillRectangle(backbrush, rowBounds) Finally backbrush.Dispose() End Try End If End Sub 'dataGridView1_RowPrePaint
// Paints the custom selection background for selected rows. void dataGridView1_RowPrePaint(object sender, DataGridViewRowPrePaintEventArgs e) { // Do not automatically paint the focus rectangle. e.PaintParts &= ~DataGridViewPaintParts.Focus; // Determine whether the cell should be painted // with the custom selection background. if ((e.State & DataGridViewElementStates.Selected) == DataGridViewElementStates.Selected) { // 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); // Paint the custom selection background. using (Brush backbrush = new System.Drawing.Drawing2D.LinearGradientBrush(rowBounds , this.dataGridView1.DefaultCellStyle.SelectionBackColor , e.InheritedRowStyle.ForeColor, System.Drawing.Drawing2D.LinearGradientMode.Horizontal)) { e.Graphics.FillRectangle(backbrush, rowBounds); } } }

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.RowPrePaint イベントを検索する場合は、下記のリンクをクリックしてください。

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