DataGridViewPaintParts 枚举

定义

定义用于指定要绘制的 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
继承
DataGridViewPaintParts
属性

字段

All 127

应绘制单元格的所有部分。All parts of the cell should be painted.

Background 1

应绘制单元格的背景。The background of the cell should be painted.

Border 2

应绘制单元格的边框。The border of the cell should be painted.

ContentBackground 4

应绘制单元格内容的背景。The background of the cell content should be painted.

ContentForeground 8

应绘制单元格内容的前景。The foreground of the cell content should be painted.

ErrorIcon 16

应绘制单元格错误图标。The cell error icon should be painted.

Focus 32

应当在单元格周围绘制聚焦框。The focus rectangle should be painted around the cell.

None 0

不应绘制任何内容。Nothing should be painted.

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

注解

此枚举由受DataGridViewCell.Paint保护的方法以及DataGridView控件的CellPaintingRowPrePaintRowPostPaint事件的处理程序使用。This enumeration is used by the protected DataGridViewCell.Paint method and by handlers for the CellPainting, RowPrePaint, and RowPostPaint events of the DataGridView control.

适用于

另请参阅