DataGridViewPaintParts Enumeração
Definição
Importante
Algumas informações dizem respeito a um produto pré-lançado que pode ser substancialmente modificado antes de ser lançado. A Microsoft não faz garantias, de forma expressa ou implícita, em relação à informação aqui apresentada.
Define valores para especificar as partes de um DataGridViewCell que devem ser pintadas.
Esta enumeração suporta uma combinação bit-a-bit dos respetivos valores membro.
public enum class DataGridViewPaintParts
[System.Flags]
public enum DataGridViewPaintParts
[<System.Flags>]
type DataGridViewPaintParts =
Public Enum DataGridViewPaintParts
- Herança
- Atributos
Campos
| Name | Valor | Description |
|---|---|---|
| None | 0 | Nada deve ser pintado. |
| Background | 1 | O fundo da cela deve ser pintado. |
| Border | 2 | A borda da cela deve ser pintada. |
| ContentBackground | 4 | O fundo do conteúdo da célula deve ser pintado. |
| ContentForeground | 8 | O primeiro plano do conteúdo da célula deve ser pintado. |
| ErrorIcon | 16 | O ícone de erro de célula deve estar pintado. |
| Focus | 32 | O retângulo de foco deve ser pintado à volta da célula. |
| SelectionBackground | 64 | O fundo da célula deve ser pintado quando a célula é selecionada. |
| All | 127 | Todas as partes da célula devem ser pintadas. |
Exemplos
O exemplo de código seguinte ilustra o uso deste tipo. Este exemplo faz parte de um exemplo maior disponível em Como: Personalizar a Aparência das Linhas no Controlo Windows Forms DataGridView.
// 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
Observações
Esta enumeração é usada pelo método protegido DataGridViewCell.Paint e pelos manipuladores para os CellPainting, RowPrePaint, e RowPostPaint eventos do DataGridView controlo.