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


CellPainting イベントは、DataGridView 上に表示される各 DataGridViewCell に対して発生します。パフォーマンスを向上するには、DataGridView のセルに直接アクセスする代わりに、DataGridViewCellPaintingEventArgs のプロパティを設定してセルの外観を変更します。手動でセルを描画するには、HandledEventArgs.Handled プロパティを true に設定します。HandledEventArgs.Handled を true に設定しないと、セルをカスタマイズした内容が上書き描画されます。

この型の使用方法を次のコード例に示します。詳細については、「方法 : Windows フォームの DataGridView コントロールのセルの外観をカスタマイズする」を参照してください。
Private Sub dataGridView1_CellPainting(ByVal sender As Object, _ ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) _ Handles dataGridView1.CellPainting If Me.dataGridView1.Columns("ContactName").Index = _ e.ColumnIndex AndAlso e.RowIndex >= 0 Then Dim newRect As New Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, _ e.CellBounds.Width - 4, e.CellBounds.Height - 4) Dim backColorBrush As New SolidBrush(e.CellStyle.BackColor) Dim gridBrush As New SolidBrush(Me.dataGridView1.GridColor) Dim gridLinePen As New Pen(gridBrush) Try ' Erase the cell. e.Graphics.FillRectangle(backColorBrush, e.CellBounds) ' Draw the grid lines (only the right and bottom lines; ' DataGridView takes care of the others). e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, _ e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, _ e.CellBounds.Bottom - 1) e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, _ e.CellBounds.Top, e.CellBounds.Right - 1, _ e.CellBounds.Bottom) ' Draw the inset highlight box. e.Graphics.DrawRectangle(Pens.Blue, newRect) ' Draw the text content of the cell, ignoring alignment. If Not (e.Value Is Nothing) Then e.Graphics.DrawString(CStr(e.Value), e.CellStyle.Font, _ Brushes.Crimson, e.CellBounds.X + 2, e.CellBounds.Y + 2, _ StringFormat.GenericDefault) End If e.Handled = True Finally gridLinePen.Dispose() gridBrush.Dispose() backColorBrush.Dispose() End Try End If End Sub
private void dataGridView1_CellPainting(object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e) { if (this.dataGridView1.Columns["ContactName"].Index == e.ColumnIndex && e.RowIndex >= 0) { Rectangle newRect = new Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, e.CellBounds.Width - 4, e.CellBounds.Height - 4); using ( Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor) , backColorBrush = new SolidBrush(e.CellStyle.BackColor)) { using (Pen gridLinePen = new Pen(gridBrush)) { // Erase the cell. e.Graphics.FillRectangle(backColorBrush, e.CellBounds); // Draw the grid lines (only the right and bottom lines; // DataGridView takes care of the others). e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, e.CellBounds.Bottom - 1); e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, e.CellBounds.Top, e.CellBounds.Right - 1, e.CellBounds.Bottom); // Draw the inset highlight box. e.Graphics.DrawRectangle(Pens.Blue, newRect); // Draw the text content of the cell, ignoring alignment. if (e.Value != null) { e.Graphics.DrawString((String)e.Value, e.CellStyle.Font, Brushes.Crimson, e.CellBounds.X + 2, e.CellBounds.Y + 2, StringFormat.GenericDefault); } e.Handled = true; } } } }

System.EventArgs
System.ComponentModel.HandledEventArgs
System.Windows.Forms.DataGridViewCellPaintingEventArgs


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


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

Public Sub New ( _ dataGridView As DataGridView, _ graphics As Graphics, _ clipBounds As Rectangle, _ cellBounds As Rectangle, _ rowIndex As Integer, _ columnIndex As Integer, _ cellState As DataGridViewElementStates, _ value As Object, _ formattedValue As Object, _ errorText As String, _ cellStyle As DataGridViewCellStyle, _ advancedBorderStyle As DataGridViewAdvancedBorderStyle, _ paintParts As DataGridViewPaintParts _ )
Dim dataGridView As DataGridView Dim graphics As Graphics Dim clipBounds As Rectangle Dim cellBounds As Rectangle Dim rowIndex As Integer Dim columnIndex As Integer Dim cellState As DataGridViewElementStates Dim value As Object Dim formattedValue As Object Dim errorText As String Dim cellStyle As DataGridViewCellStyle Dim advancedBorderStyle As DataGridViewAdvancedBorderStyle Dim paintParts As DataGridViewPaintParts Dim instance As New DataGridViewCellPaintingEventArgs(dataGridView, graphics, clipBounds, cellBounds, rowIndex, columnIndex, cellState, value, formattedValue, errorText, cellStyle, advancedBorderStyle, paintParts)
public DataGridViewCellPaintingEventArgs ( DataGridView dataGridView, Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, int columnIndex, DataGridViewElementStates cellState, Object value, Object formattedValue, string errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts )
public: DataGridViewCellPaintingEventArgs ( DataGridView^ dataGridView, Graphics^ graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, int columnIndex, DataGridViewElementStates cellState, Object^ value, Object^ formattedValue, String^ errorText, DataGridViewCellStyle^ cellStyle, DataGridViewAdvancedBorderStyle^ advancedBorderStyle, DataGridViewPaintParts paintParts )
public DataGridViewCellPaintingEventArgs ( DataGridView dataGridView, Graphics graphics, Rectangle clipBounds, Rectangle cellBounds, int rowIndex, int columnIndex, DataGridViewElementStates cellState, Object value, Object formattedValue, String errorText, DataGridViewCellStyle cellStyle, DataGridViewAdvancedBorderStyle advancedBorderStyle, DataGridViewPaintParts paintParts )
public function DataGridViewCellPaintingEventArgs ( dataGridView : DataGridView, graphics : Graphics, clipBounds : Rectangle, cellBounds : Rectangle, rowIndex : int, columnIndex : int, cellState : DataGridViewElementStates, value : Object, formattedValue : Object, errorText : String, cellStyle : DataGridViewCellStyle, advancedBorderStyle : DataGridViewAdvancedBorderStyle, paintParts : DataGridViewPaintParts )


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 によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


DataGridViewCellPaintingEventArgs プロパティ

名前 | 説明 | |
---|---|---|
![]() | AdvancedBorderStyle | 現在の DataGridViewCell の境界線スタイルを取得します。 |
![]() | CellBounds | 現在の DataGridViewCell の境界を取得します。 |
![]() | CellStyle | 現在の DataGridViewCell のセル スタイルを取得します。 |
![]() | ClipBounds | 再描画が必要な DataGridView の領域を取得します。 |
![]() | ColumnIndex | 現在の DataGridViewCell の列インデックスを取得します。 |
![]() | ErrorText | 現在の DataGridViewCell のエラー メッセージを表す文字列を取得します。 |
![]() | FormattedValue | 現在の DataGridViewCell の書式設定した値を取得します。 |
![]() | Graphics | 現在の DataGridViewCell の描画に使用される Graphics を取得します。 |
![]() | Handled | イベント ハンドラがイベントを完全に処理したかどうか、またはシステムが独自の処理を継続する必要があるかどうかを示す値を取得または設定します。 ( HandledEventArgs から継承されます。) |
![]() | PaintParts | 描画されるセル部分。 |
![]() | RowIndex | 現在の DataGridViewCell の行インデックスを取得します。 |
![]() | State | 現在の DataGridViewCell の状態を取得します。 |
![]() | Value | 現在の DataGridViewCell の値を取得します。 |

DataGridViewCellPaintingEventArgs メソッド

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

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

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


名前 | 説明 | |
---|---|---|
![]() | AdvancedBorderStyle | 現在の DataGridViewCell の境界線スタイルを取得します。 |
![]() | CellBounds | 現在の DataGridViewCell の境界を取得します。 |
![]() | CellStyle | 現在の DataGridViewCell のセル スタイルを取得します。 |
![]() | ClipBounds | 再描画が必要な DataGridView の領域を取得します。 |
![]() | ColumnIndex | 現在の DataGridViewCell の列インデックスを取得します。 |
![]() | ErrorText | 現在の DataGridViewCell のエラー メッセージを表す文字列を取得します。 |
![]() | FormattedValue | 現在の DataGridViewCell の書式設定した値を取得します。 |
![]() | Graphics | 現在の DataGridViewCell の描画に使用される Graphics を取得します。 |
![]() | Handled | イベント ハンドラがイベントを完全に処理したかどうか、またはシステムが独自の処理を継続する必要があるかどうかを示す値を取得または設定します。(HandledEventArgs から継承されます。) |
![]() | PaintParts | 描画されるセル部分。 |
![]() | RowIndex | 現在の DataGridViewCell の行インデックスを取得します。 |
![]() | State | 現在の DataGridViewCell の状態を取得します。 |
![]() | Value | 現在の DataGridViewCell の値を取得します。 |

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

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

Weblioに収録されているすべての辞書からDataGridViewCellPaintingEventArgsを検索する場合は、下記のリンクをクリックしてください。

- DataGridViewCellPaintingEventArgsのページへのリンク