DataGridViewRowPrePaintEventArgs.RowBounds Propiedad

Definición

Obtiene los límites de la celda DataGridViewRow actual.

public:
 property System::Drawing::Rectangle RowBounds { System::Drawing::Rectangle get(); };
public System.Drawing.Rectangle RowBounds { get; }
member this.RowBounds : System.Drawing.Rectangle
Public ReadOnly Property RowBounds As Rectangle

Valor de propiedad

Rectangle que representa los límites de la celda DataGridViewRow actual.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la RowBounds propiedad para calcular los límites de la fila para pintar un fondo personalizado. La variable , ees de tipo DataGridViewRowPrePaintEventArgs. 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.

// 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);
    }
}
' 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

Comentarios

El ancho de la RowBounds propiedad es el mismo que el ancho de .DataGridView Para obtener el ancho de las columnas de DataGridView, use el GetColumnsWidth método .

Se aplica a

Consulte también