DrawListViewItemEventArgs.Bounds Propiedad

Definición

Obtiene el tamaño y la ubicación del control ListViewItem que se va a dibujar.

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

Valor de propiedad

Estructura Rectangle que representa los límites del control ListViewItem que se va a dibujar.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la Bounds propiedad en una aplicación que proporciona un dibujo personalizado para un ListView control . En el ejemplo, un controlador para el ListView.DrawItem evento dibuja el fondo de elementos completos. En todas las vistas excepto la vista de detalles, este controlador también dibuja el texto en primer plano. En la vista de detalles, el texto en primer plano se dibuja en el ListView.DrawSubItem evento .

Para obtener el ejemplo completo, consulte el DrawListViewItemEventArgs tema de referencia de información general.

// Draws the backgrounds for entire ListView items.
private void listView1_DrawItem(object sender,
    DrawListViewItemEventArgs e)
{
    if ((e.State & ListViewItemStates.Selected) != 0)
    {
        // Draw the background and focus rectangle for a selected item.
        e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds);
        e.DrawFocusRectangle();
    }
    else
    {
        // Draw the background for an unselected item.
        using (LinearGradientBrush brush =
            new LinearGradientBrush(e.Bounds, Color.Orange,
            Color.Maroon, LinearGradientMode.Horizontal))
        {
            e.Graphics.FillRectangle(brush, e.Bounds);
        }
    }

    // Draw the item text for views other than the Details view.
    if (listView1.View != View.Details)
    {
        e.DrawText();
    }
}
' Draws the backgrounds for entire ListView items.
Private Sub listView1_DrawItem(ByVal sender As Object, _
    ByVal e As DrawListViewItemEventArgs) _
    Handles listView1.DrawItem

    If Not (e.State And ListViewItemStates.Selected) = 0 Then

        ' Draw the background for a selected item.
        e.Graphics.FillRectangle(Brushes.Maroon, e.Bounds)
        e.DrawFocusRectangle()

    Else

        ' Draw the background for an unselected item.
        Dim brush As New LinearGradientBrush(e.Bounds, Color.Orange, _
            Color.Maroon, LinearGradientMode.Horizontal)
        Try
            e.Graphics.FillRectangle(brush, e.Bounds)
        Finally
            brush.Dispose()
        End Try

    End If

    ' Draw the item text for views other than the Details view.
    If Not Me.listView1.View = View.Details Then
        e.DrawText()
    End If

End Sub

Comentarios

La ubicación especificada por esta propiedad es relativa a la esquina superior izquierda del ListView control.

Para recuperar los límites de partes específicas de , ListViewItemuse el ListViewItem.GetBounds método .

Se aplica a

Consulte también