DataGridViewRowPrePaintEventArgs Clase
Definició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í.
Proporciona datos para el evento RowPrePaint.
public ref class DataGridViewRowPrePaintEventArgs : System::ComponentModel::HandledEventArgs
public class DataGridViewRowPrePaintEventArgs : System.ComponentModel.HandledEventArgs
type DataGridViewRowPrePaintEventArgs = class
inherit HandledEventArgs
Public Class DataGridViewRowPrePaintEventArgs
Inherits HandledEventArgs
- Herencia
Ejemplos
En el ejemplo de código siguiente se muestra cómo controlar el RowPrePaint evento para dibujar un fondo personalizado para las celdas seleccionadas. Este ejemplo de código forma parte de un ejemplo más grande proporcionado 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
Comentarios
El RowPrePaint evento se produce antes de pintar una fila en un DataGridView control . RowPrePaint permite ajustar manualmente la apariencia de la fila antes de que se pinte cualquiera de las celdas de la fila. Esto resulta útil si desea personalizar la fila, por ejemplo, para generar una fila en la que el contenido de una columna abarca varias columnas. Use las propiedades de DataGridViewRowPrePaintEventArgs para obtener la configuración de la fila sin tener acceso directo a la fila en DataGridView.
Constructores
| Nombre | Description |
|---|---|
| DataGridViewRowPrePaintEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, DataGridViewElementStates, String, DataGridViewCellStyle, Boolean, Boolean) |
Inicializa una nueva instancia de la clase DataGridViewRowPrePaintEventArgs. |
Propiedades
| Nombre | Description |
|---|---|
| ClipBounds |
Obtiene o establece el área de que DataGridView se debe volver a dibujar. |
| ErrorText |
Obtiene una cadena que representa un mensaje de error para el objeto actual DataGridViewRow. |
| Graphics |
Obtiene el Graphics objeto utilizado para pintar el objeto actual DataGridViewRow. |
| Handled |
Obtiene o establece un valor que indica si el controlador de eventos ha controlado completamente el evento o si el sistema debe continuar su propio procesamiento. (Heredado de HandledEventArgs) |
| InheritedRowStyle |
Obtiene el estilo de celda aplicado a la fila. |
| IsFirstDisplayedRow |
Obtiene un valor que indica si la fila actual es la primera fila que se muestra actualmente en .DataGridView |
| IsLastVisibleRow |
Obtiene un valor que indica si la fila actual es la última fila visible en .DataGridView |
| PaintParts |
Partes de celda que se van a pintar. |
| RowBounds |
Obtenga los límites del objeto actual DataGridViewRow. |
| RowIndex |
Obtiene el índice del objeto actual DataGridViewRow. |
| State |
Obtiene el estado del objeto actual DataGridViewRow. |
Métodos
| Nombre | Description |
|---|---|
| DrawFocus(Rectangle, Boolean) |
Dibuja el rectángulo de foco alrededor de los límites especificados. |
| Equals(Object) |
Determina si el objeto especificado es igual al objeto actual. (Heredado de Object) |
| GetHashCode() |
Actúa como la función hash predeterminada. (Heredado de Object) |
| GetType() |
Obtiene el Type de la instancia actual. (Heredado de Object) |
| MemberwiseClone() |
Crea una copia superficial del Objectactual. (Heredado de Object) |
| PaintCells(Rectangle, DataGridViewPaintParts) |
Pinta las partes de celda especificadas para el área de los límites especificados. |
| PaintCellsBackground(Rectangle, Boolean) |
Pinta los fondos de celda para el área de los límites especificados. |
| PaintCellsContent(Rectangle) |
Pinta el contenido de la celda para el área de los límites especificados. |
| PaintHeader(Boolean) |
Pinta el encabezado de fila completo del objeto actual DataGridViewRow. |
| PaintHeader(DataGridViewPaintParts) |
Pinta las partes especificadas del encabezado de fila de la fila actual. |
| ToString() |
Devuelve una cadena que representa el objeto actual. (Heredado de Object) |