DataGridViewCellPaintingEventArgs Clase

Definición

Proporciona datos para el evento CellPainting.Provides data for the CellPainting event.

public ref class DataGridViewCellPaintingEventArgs : System::ComponentModel::HandledEventArgs
public class DataGridViewCellPaintingEventArgs : System.ComponentModel.HandledEventArgs
type DataGridViewCellPaintingEventArgs = class
    inherit HandledEventArgs
Public Class DataGridViewCellPaintingEventArgs
Inherits HandledEventArgs
Herencia
DataGridViewCellPaintingEventArgs

Ejemplos

En el ejemplo de código siguiente se muestra el uso de este tipo.The following code example illustrates the use of this type. Para obtener más información, consulte Cómo Personalice la apariencia de las celdas en el controlDataGridView Windows Forms.For more information, see How to: Customize the Appearance of Cells in the Windows Forms DataGridView Control.

private void dataGridView1_CellPainting(object sender,
System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
{
    if (this.dataGridView1.Columns["ContactName"].Index ==
        e.ColumnIndex && e.RowIndex >= 0)
    {
        Rectangle newRect = new Rectangle(e.CellBounds.X + 1,
            e.CellBounds.Y + 1, e.CellBounds.Width - 4,
            e.CellBounds.Height - 4);

        using (
            Brush gridBrush = new SolidBrush(this.dataGridView1.GridColor),
            backColorBrush = new SolidBrush(e.CellStyle.BackColor))
        {
            using (Pen gridLinePen = new Pen(gridBrush))
            {
                // Erase the cell.
                e.Graphics.FillRectangle(backColorBrush, e.CellBounds);

                // Draw the grid lines (only the right and bottom lines;
                // DataGridView takes care of the others).
                e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left,
                    e.CellBounds.Bottom - 1, e.CellBounds.Right - 1,
                    e.CellBounds.Bottom - 1);
                e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1,
                    e.CellBounds.Top, e.CellBounds.Right - 1,
                    e.CellBounds.Bottom);

                // Draw the inset highlight box.
                e.Graphics.DrawRectangle(Pens.Blue, newRect);

                // Draw the text content of the cell, ignoring alignment.
                if (e.Value != null)
                {
                    e.Graphics.DrawString((String)e.Value, e.CellStyle.Font,
                        Brushes.Crimson, e.CellBounds.X + 2,
                        e.CellBounds.Y + 2, StringFormat.GenericDefault);
                }
                e.Handled = true;
            }
        }
    }
}
Private Sub dataGridView1_CellPainting(ByVal sender As Object, _
    ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) _
    Handles dataGridView1.CellPainting

    If Me.dataGridView1.Columns("ContactName").Index = _
        e.ColumnIndex AndAlso e.RowIndex >= 0 Then

        Dim newRect As New Rectangle(e.CellBounds.X + 1, e.CellBounds.Y + 1, _
            e.CellBounds.Width - 4, e.CellBounds.Height - 4)
        Dim backColorBrush As New SolidBrush(e.CellStyle.BackColor)
        Dim gridBrush As New SolidBrush(Me.dataGridView1.GridColor)
        Dim gridLinePen As New Pen(gridBrush)

        Try

            ' Erase the cell.
            e.Graphics.FillRectangle(backColorBrush, e.CellBounds)

            ' Draw the grid lines (only the right and bottom lines;
            ' DataGridView takes care of the others).
            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Left, _
                e.CellBounds.Bottom - 1, e.CellBounds.Right - 1, _
                e.CellBounds.Bottom - 1)
            e.Graphics.DrawLine(gridLinePen, e.CellBounds.Right - 1, _
                e.CellBounds.Top, e.CellBounds.Right - 1, _
                e.CellBounds.Bottom)

            ' Draw the inset highlight box.
            e.Graphics.DrawRectangle(Pens.Blue, newRect)

            ' Draw the text content of the cell, ignoring alignment.
            If (e.Value IsNot Nothing) Then
                e.Graphics.DrawString(CStr(e.Value), e.CellStyle.Font, _
                Brushes.Crimson, e.CellBounds.X + 2, e.CellBounds.Y + 2, _
                StringFormat.GenericDefault)
            End If
            e.Handled = True

        Finally
            gridLinePen.Dispose()
            gridBrush.Dispose()
            backColorBrush.Dispose()
        End Try

    End If

End Sub

Comentarios

El CellPainting evento se genera para cada DataGridViewCell DataGridViewque está visible en.The CellPainting event is raised for each DataGridViewCell that is visible on a DataGridView. Para mejorar el rendimiento, establezca las propiedades de DataGridViewCellPaintingEventArgs un para cambiar el aspecto de la celda en lugar de obtener acceso directamente a una celda DataGridViewde.To improve performance, set the properties in a DataGridViewCellPaintingEventArgs to change the appearance of the cell instead of directly accessing a cell in the DataGridView. Si pinta la celda manualmente, establezca la HandledEventArgs.Handled propiedad en. trueIf you manually paint the cell, set the HandledEventArgs.Handled property to true. Si no establece HandledEventArgs.Handled en true, la celda se dibujará sobre las personalizaciones.If you do not set HandledEventArgs.Handled to true, the cell will paint over your customizations.

Constructores

DataGridViewCellPaintingEventArgs(DataGridView, Graphics, Rectangle, Rectangle, Int32, Int32, DataGridViewElementStates, Object, Object, String, DataGridViewCellStyle, DataGridViewAdvancedBorderStyle, DataGridViewPaintParts)

Inicializa una nueva instancia de la clase DataGridViewCellPaintingEventArgs.Initializes a new instance of the DataGridViewCellPaintingEventArgs class.

Propiedades

AdvancedBorderStyle

Obtiene el estilo de borde de la celda DataGridViewCell actual.Gets the border style of the current DataGridViewCell.

CellBounds

Obtiene los límites de la celda DataGridViewCell actual.Get the bounds of the current DataGridViewCell.

CellStyle

Obtiene el estilo de celda de la celda DataGridViewCell actual.Gets the cell style of the current DataGridViewCell.

ClipBounds

Obtiene el área de DataGridView que es necesario volver a dibujar.Gets the area of the DataGridView that needs to be repainted.

ColumnIndex

Obtiene el índice de columna de la celda DataGridViewCell actual.Gets the column index of the current DataGridViewCell.

ErrorText

Obtiene una cadena que representa un mensaje de error para la celda DataGridViewCell actual.Gets a string that represents an error message for the current DataGridViewCell.

FormattedValue

Obtiene el valor con formato de la celda DataGridViewCell actual.Gets the formatted value of the current DataGridViewCell.

Graphics

Obtiene el objeto Graphics que se utiliza para dibujar la celda DataGridViewCell actual.Gets the Graphics used to paint the current DataGridViewCell.

Handled

Obtiene o establece un valor que indica si el controlador de eventos ha controlado completamente el evento o si el sistema debe continuar con su propio procesamiento.Gets or sets a value that indicates whether the event handler has completely handled the event or whether the system should continue its own processing.

(Heredado de HandledEventArgs)
PaintParts

Partes de la celda que se van a dibujar.The cell parts that are to be painted.

RowIndex

Obtiene el índice de fila de la celda DataGridViewCell actual.Gets the row index of the current DataGridViewCell.

State

Obtiene el estado de la celda DataGridViewCell actual.Gets the state of the current DataGridViewCell.

Value

Obtiene el valor de la celda DataGridViewCell actual.Gets the value of the current DataGridViewCell.

Métodos

Equals(Object)

Determina si el objeto especificado es igual al objeto actual.Determines whether the specified object is equal to the current object.

(Heredado de Object)
GetHashCode()

Sirve como la función hash predeterminada.Serves as the default hash function.

(Heredado de Object)
GetType()

Obtiene el Type de la instancia actual.Gets the Type of the current instance.

(Heredado de Object)
MemberwiseClone()

Crea una copia superficial del objeto Object actual.Creates a shallow copy of the current Object.

(Heredado de Object)
Paint(Rectangle, DataGridViewPaintParts)

Dibuja las partes especificadas de la celda para el área comprendida entre los límites especificados.Paints the specified parts of the cell for the area in the specified bounds.

PaintBackground(Rectangle, Boolean)

Pinta el fondo de celda del área comprendida entre los límites especificados.Paints the cell background for the area in the specified bounds.

PaintContent(Rectangle)

Dibuja el contenido de celda del área comprendida entre los límites especificados.Paints the cell content for the area in the specified bounds.

ToString()

Devuelve una cadena que representa el objeto actual.Returns a string that represents the current object.

(Heredado de Object)

Se aplica a

Consulte también: