DataGridViewPaintParts Enumeración
Importante
Parte de la información hace referencia a la versión preliminar del producto, que puede haberse modificado sustancialmente antes de lanzar la versión definitiva. Microsoft no otorga ninguna garantía, explícita o implícita, con respecto a la información proporcionada aquí.
Define valores para especificar las partes de un DataGridViewCell que se pintarán.
Esta enumeración admite una combinación bit a bit de sus valores de miembro.
public enum class DataGridViewPaintParts
[System.Flags]
public enum DataGridViewPaintParts
[<System.Flags>]
type DataGridViewPaintParts =
Public Enum DataGridViewPaintParts
- Herencia
- Atributos
Nombre | Valor | Description |
---|---|---|
All | 127 | Se deben pintar todas las partes de la celda. |
Background | 1 | Se debe pintar el fondo de la celda. |
Border | 2 | Se debe pintar el borde de la celda. |
ContentBackground | 4 | Se debe pintar el fondo del contenido de la celda. |
ContentForeground | 8 | Se debe pintar el primer plano del contenido de la celda. |
ErrorIcon | 16 | Se debe pintar el icono de error de celda. |
Focus | 32 | Se debe pintar el rectángulo de foco alrededor de la celda. |
None | 0 | No se debe pintar nada. |
SelectionBackground | 64 | Se debe pintar el fondo de la celda cuando la celda esté seleccionada. |
En el ejemplo de código siguiente se muestra el uso de este tipo. Este ejemplo forma parte de un ejemplo más grande disponible en 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
Este método protegido DataGridViewCell.Paint usa esta enumeración y los controladores para los CellPaintingeventos , RowPrePainty RowPostPaint del DataGridView control .
Producto | Versiones |
---|---|
.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 |
Comentarios de .NET
.NET es un proyecto de código abierto. Seleccione un vínculo para proporcionar comentarios: