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.

适用于

另请参阅