DataGridViewCellPaintingEventArgs DataGridViewCellPaintingEventArgs DataGridViewCellPaintingEventArgs DataGridViewCellPaintingEventArgs Class

定義

CellPainting イベントのデータを提供します。Provides data for the CellPainting event.

public ref class DataGridViewCellPaintingEventArgs : System::ComponentModel::HandledEventArgs
public class DataGridViewCellPaintingEventArgs : System.ComponentModel.HandledEventArgs
type DataGridViewCellPaintingEventArgs = class
    inherit HandledEventArgs
Public Class DataGridViewCellPaintingEventArgs
Inherits HandledEventArgs
継承
DataGridViewCellPaintingEventArgsDataGridViewCellPaintingEventArgsDataGridViewCellPaintingEventArgsDataGridViewCellPaintingEventArgs

次のコード例は、この型の使用を示しています。The following code example illustrates the use of this type. 詳細については、「方法 :Windows フォームの DataGridView コントロール内のセルの外観をカスタマイズします。For more information, see How to: Customize the Appearance of Cells in the Windows Forms DataGridView Control.

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;
            }
        }
    }
}
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 (e.Value IsNot 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

注釈

CellPaintingイベントは各DataGridViewCellで表示されている、DataGridViewします。The CellPainting event is raised for each DataGridViewCell that is visible on a DataGridView. パフォーマンスを向上させるでプロパティを設定、DataGridViewCellPaintingEventArgs内のセルに直接アクセスするのではなく、セルの外観を変更する、DataGridViewします。To improve performance, set the properties in a DataGridViewCellPaintingEventArgs to change the appearance of the cell instead of directly accessing a cell in the DataGridView. セルを手動で描画する場合は、設定、HandledEventArgs.Handledプロパティをtrueします。If you manually paint the cell, set the HandledEventArgs.Handled property to true. 設定しない場合HandledEventArgs.Handledtrueセルがカスタマイズした内容を描画します。If you do not set HandledEventArgs.Handled to true, the cell will paint over your customizations.

コンストラクター

DataGridViewCellPaintingEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts) DataGridViewCellPaintingEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts) DataGridViewCellPaintingEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts) DataGridViewCellPaintingEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts)

DataGridViewCellPaintingEventArgs クラスの新しいインスタンスを初期化します。Initializes a new instance of the DataGridViewCellPaintingEventArgs class.

プロパティ

AdvancedBorderStyle AdvancedBorderStyle AdvancedBorderStyle AdvancedBorderStyle

現在の DataGridViewCell の境界線スタイルを取得します。Gets the border style of the current DataGridViewCell.

CellBounds CellBounds CellBounds CellBounds

現在の DataGridViewCell の境界を取得します。Get the bounds of the current DataGridViewCell.

CellStyle CellStyle CellStyle CellStyle

現在の DataGridViewCell のセル スタイルを取得します。Gets the cell style of the current DataGridViewCell.

ClipBounds ClipBounds ClipBounds ClipBounds

再描画が必要な DataGridView の領域を取得します。Gets the area of the DataGridView that needs to be repainted.

ColumnIndex ColumnIndex ColumnIndex ColumnIndex

現在の DataGridViewCell の列インデックスを取得します。Gets the column index of the current DataGridViewCell.

ErrorText ErrorText ErrorText ErrorText

現在の DataGridViewCell のエラー メッセージを表す文字列を取得します。Gets a string that represents an error message for the current DataGridViewCell.

FormattedValue FormattedValue FormattedValue FormattedValue

現在の DataGridViewCell の書式設定した値を取得します。Gets the formatted value of the current DataGridViewCell.

Graphics Graphics Graphics Graphics

現在の Graphics の描画に使用される DataGridViewCell を取得します。Gets the Graphics used to paint the current DataGridViewCell.

Handled Handled Handled Handled

イベント ハンドラーがイベントを完全に処理したかどうか、またはシステムが独自の処理を継続する必要があるかどうかを示す値を取得または設定します。Gets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing.

(Inherited from HandledEventArgs)
PaintParts PaintParts PaintParts PaintParts

描画されるセル部分。The cell parts that are to be painted.

RowIndex RowIndex RowIndex RowIndex

現在の DataGridViewCell の行インデックスを取得します。Gets the row index of the current DataGridViewCell.

State State State State

現在の DataGridViewCell の状態を取得します。Gets the state of the current DataGridViewCell.

Value Value Value Value

現在の DataGridViewCell の値を取得します。Gets the value of the current DataGridViewCell.

メソッド

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

指定したオブジェクトが、現在のオブジェクトと等しいかどうかを判断します。Determines whether the specified object is equal to the current object.

(Inherited from Object)
GetHashCode() GetHashCode() GetHashCode() GetHashCode()

既定のハッシュ関数として機能します。Serves as the default hash function.

(Inherited from Object)
GetType() GetType() GetType() GetType()

現在のインスタンスの Type を取得します。Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

現在の Object の簡易コピーを作成します。Creates a shallow copy of the current Object.

(Inherited from Object)
Paint(Rectangle, DataGridViewPaintParts) Paint(Rectangle, DataGridViewPaintParts) Paint(Rectangle, DataGridViewPaintParts) Paint(Rectangle, DataGridViewPaintParts)

指定した境界内の領域に対応するセルの指定した部分を描画します。Paints the specified parts of the cell for the area in the specified bounds.

PaintBackground(Rectangle, Boolean) PaintBackground(Rectangle, Boolean) PaintBackground(Rectangle, Boolean) PaintBackground(Rectangle, Boolean)

指定した境界内の領域のセルの背景を描画します。Paints the cell background for the area in the specified bounds.

PaintContent(Rectangle) PaintContent(Rectangle) PaintContent(Rectangle) PaintContent(Rectangle)

指定した境界内の領域のセルの内容を描画します。Paints the cell content for the area in the specified bounds.

ToString() ToString() ToString() ToString()

現在のオブジェクトを表す文字列を返します。Returns a string that represents the current object.

(Inherited from Object)

適用対象

こちらもご覧ください