DrawListViewItemEventArgs.Graphics Propiedad

Definición

Obtiene el Graphics usado para dibujar el ListViewItem.

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

Valor de propiedad

Objeto Graphics que se utiliza para dibujar el control ListViewItem.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la Graphics 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 Graphics clase proporciona propiedades y métodos útiles para dibujar en el dispositivo de visualización.

Se aplica a

Consulte también