英語で読む

次の方法で共有


DataGridViewPaintParts 列挙型

定義

描画される DataGridViewCell の部分を指定するための値を定義します。

この列挙体は、メンバー値のビットごとの組み合わせをサポートしています。

C#
[System.Flags]
public enum DataGridViewPaintParts
継承
DataGridViewPaintParts
属性

フィールド

名前 説明
All 127

セルのすべての部分を描画する必要があります。

Background 1

セルの背景を描画する必要があります。

Border 2

セルの境界線を描画する必要があります。

ContentBackground 4

セルの内容の背景を描画する必要があります。

ContentForeground 8

セルの内容の前景を描画する必要があります。

ErrorIcon 16

セルのエラー アイコンを描画する必要があります。

Focus 32

セルの周囲にフォーカスを示す四角形を描画する必要があります。

None 0

何も描画しません。

SelectionBackground 64

セルが選択されたときに、セルの背景を描画する必要があります。

次のコード例は、この型の使用方法を示しています。 この例は、「方法: Windows フォーム DataGridView コントロールの行の外観をカスタマイズする」で使用できるより大きな例の一部です。

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

注釈

この列挙は、保護されたDataGridViewCell.Paintメソッドと、コントロールの 、RowPrePaint、および RowPostPaint イベントのハンドラーCellPaintingによって使用されますDataGridView

適用対象

製品 バージョン
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

こちらもご覧ください