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

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

DataGridViewCellPaintingEventArgs クラス

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

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

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

Public Class DataGridViewCellPaintingEventArgs
    Inherits HandledEventArgs
Dim instance As DataGridViewCellPaintingEventArgs
public class DataGridViewCellPaintingEventArgs
 : HandledEventArgs
public ref class DataGridViewCellPaintingEventArgs
 : public HandledEventArgs
public class DataGridViewCellPaintingEventArgs
 extends HandledEventArgs
public class DataGridViewCellPaintingEventArgs
 extends HandledEventArgs
解説解説

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.Object
   System.EventArgs
     System.ComponentModel.HandledEventArgs
      System.Windows.Forms.DataGridViewCellPaintingEventArgs
スレッド セーフスレッド セーフ
この型の public static (Visual Basic では Shared) メンバはすべて、スレッド セーフです。インスタンス メンバの場合は、スレッド セーフであるとは限りません。
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridViewCellPaintingEventArgs メンバ
System.Windows.Forms 名前空間
DataGridView.CellPainting イベント
DataGridViewCell クラス
DataGridView クラス

DataGridViewCellPaintingEventArgs コンストラクタ

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

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

名前空間: System.Windows.Forms
アセンブリ: 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
)

パラメータ

dataGridView

描画されるセルを含んだ DataGridView。

graphics

DataGridViewCell の描画に使用する Graphics。

clipBounds

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

cellBounds

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

rowIndex

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

columnIndex

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

cellState

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

value

描画される DataGridViewCell のデータ。

formattedValue

描画される DataGridViewCell の書式設定したデータ。

errorText

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

cellStyle

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

advancedBorderStyle

描画されるセルの境界線スタイルが格納された DataGridViewAdvancedBorderStyle。

paintParts

描画する部分を指定する DataGridViewPaintParts 値のビットごとの組み合わせ。

例外例外
例外の種類条件

ArgumentNullException

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

または

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

または

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

ArgumentException

paintParts が、DataGridViewPaintParts 値の有効なビットごとの組み合わせではありません。

プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照
関連項目
DataGridViewCellPaintingEventArgs クラス
DataGridViewCellPaintingEventArgs メンバ
System.Windows.Forms 名前空間
Graphics
Rectangle
DataGridViewCell クラス
DataGridView クラス
DataGridViewElementStates
DataGridViewAdvancedBorderStyle クラス

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 クラス
System.Windows.Forms 名前空間
DataGridView.CellPainting イベント
DataGridViewCell クラス
DataGridView クラス

DataGridViewCellPaintingEventArgs メソッド


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

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

関連項目

DataGridViewCellPaintingEventArgs クラス
System.Windows.Forms 名前空間
DataGridView.CellPainting イベント
DataGridViewCell クラス
DataGridView クラス

DataGridViewCellPaintingEventArgs メンバ

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

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


パブリック コンストラクタパブリック コンストラクタ
  名前 説明
パブリック メソッド 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 の値を取得します。
パブリック メソッドパブリック メソッド
プロテクト メソッドプロテクト メソッド
参照参照

関連項目

DataGridViewCellPaintingEventArgs クラス
System.Windows.Forms 名前空間
DataGridView.CellPainting イベント
DataGridViewCell クラス
DataGridView クラス



英和和英テキスト翻訳

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

辞書ショートカット

すべての辞書の索引

「DataGridViewCellPaintingEventArgs」の関連用語

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

   

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



DataGridViewCellPaintingEventArgsのページの著作権

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

©2026 GRAS Group, Inc.RSS