Condividi tramite


DrawListViewItemEventArgs.State Proprietà

Definizione

Ottiene lo stato corrente dell'oggetto ListViewItem da disegnare.

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

Valore della proprietà

Combinazione bit per bit di ListViewItemStates valori che indica lo stato corrente dell'oggetto ListViewItem.

Esempio

Nell'esempio di codice seguente viene illustrato come utilizzare la State proprietà in un'applicazione che fornisce disegno personalizzato per un ListView controllo . Nell'esempio, un gestore per l'evento ListView.DrawItem disegna lo sfondo per l'intero elemento. In tutte le visualizzazioni, ad eccezione della visualizzazione dettagli, questo gestore disegna anche il testo in primo piano. Nella visualizzazione dei dettagli il testo in primo piano viene disegnato nell'evento ListView.DrawSubItem .

Per l'esempio completo, vedere l'argomento di riferimento di DrawListViewItemEventArgs panoramica.

// 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

Commenti

Utilizzare questa proprietà per verificare se l'oggetto ListViewItem da disegnare si trova in uno stato specifico. Questa proprietà fornisce solo informazioni sullo stato di base sull'elemento. È possibile utilizzare questa proprietà, ad esempio, per determinare se un elemento è selezionato, selezionato o attivo. Se è necessario saperne di più, recuperare l'elemento tramite la Item proprietà e controllarne direttamente le proprietà.

Si applica a

Vedi anche