DrawListViewItemEventArgs.State Propiedad

Definición

Obtiene el estado actual del control ListViewItem que se va a dibujar.

public:
 property System::Windows::Forms::ListViewItemStates State { System::Windows::Forms::ListViewItemStates get(); };
public System.Windows.Forms.ListViewItemStates State { get; }
member this.State : System.Windows.Forms.ListViewItemStates
Public ReadOnly Property State As ListViewItemStates

Valor de propiedad

Combinación bit a bit de valores ListViewItemStates que indican el estado actual del control ListViewItem.

Ejemplos

En el ejemplo de código siguiente se muestra cómo usar la State 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

Utilice esta propiedad para comprobar si el ListViewItem que se va a dibujar está en un estado determinado. Esta propiedad solo proporciona información de estado básica sobre el elemento. Puede usar esta propiedad, por ejemplo, para determinar si un elemento está seleccionado, activado o centrado. Si necesita más información, recupere el elemento a través de la Item propiedad y compruebe sus propiedades directamente.

Se aplica a

Consulte también