DataGridViewPaintParts DataGridViewPaintParts DataGridViewPaintParts DataGridViewPaintParts Enum

定義

描画される DataGridViewCell の部分を指定するための値を定義します。Defines values for specifying the parts of a DataGridViewCell that are to be painted.

この列挙型には FlagsAttribute 属性があり、メンバー値ではビットごとの組み合わせを使用できます。

public enum class DataGridViewPaintParts
[System.Flags]
public enum DataGridViewPaintParts
type DataGridViewPaintParts = 
Public Enum DataGridViewPaintParts
継承
DataGridViewPaintPartsDataGridViewPaintPartsDataGridViewPaintPartsDataGridViewPaintParts
属性

フィールド

All All All All 127

セルのすべての部分を描画する必要があります。All parts of the cell should be painted.

Background Background Background Background 1

セルの背景を描画する必要があります。The background of the cell should be painted.

Border Border Border Border 2

セルの境界線を描画する必要があります。The border of the cell should be painted.

ContentBackground ContentBackground ContentBackground ContentBackground 4

セルの内容の背景を描画する必要があります。The background of the cell content should be painted.

ContentForeground ContentForeground ContentForeground ContentForeground 8

セルの内容の前景を描画する必要があります。The foreground of the cell content should be painted.

ErrorIcon ErrorIcon ErrorIcon ErrorIcon 16

セルのエラー アイコンを描画する必要があります。The cell error icon should be painted.

Focus Focus Focus Focus 32

セルの周囲にフォーカスを示す四角形を描画する必要があります。The focus rectangle should be painted around the cell.

None None None None 0

何も描画しません。Nothing should be painted.

SelectionBackground SelectionBackground SelectionBackground SelectionBackground 64

セルが選択されたときに、セルの背景を描画する必要があります。The background of the cell should be painted when the cell is selected.

次のコード例は、この型の使用を示しています。The following code example illustrates the use of this type. この例で使用できる例の一部は、方法。Windows フォームの DataGridView コントロール内の行の外観をカスタマイズします。This example is part of a larger example available in How to: Customize the Appearance of Rows in the Windows Forms DataGridView Control.

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

注釈

この列挙体を使用して、保護されたDataGridViewCell.Paintメソッドのハンドラーで、 CellPaintingRowPrePaint、およびRowPostPaintのイベント、DataGridViewコントロール。This enumeration is used by the protected DataGridViewCell.Paint method and by handlers for the CellPainting, RowPrePaint, and RowPostPaint events of the DataGridView control.

適用対象

こちらもご覧ください