Questo argomento non è stato ancora valutato - Valuta questo argomento

Proprietà DrawListViewItemEventArgs.State

Ottiene lo stato corrente dell'elemento ListViewItem da creare.

Spazio dei nomi: System.Windows.Forms
Assembly: System.Windows.Forms (in system.windows.forms.dll)

public ListViewItemStates State { get; }
/** @property */
public ListViewItemStates get_State ()

public function get State () : ListViewItemStates

Non applicabile.

Valore proprietà

Combinazione bit per bit dei valori ListViewItemStates che indica lo stato corrente dell'elemento ListViewItem.

Utilizzare questa proprietà per controllare se l'oggetto ListViewItem da creare è in uno stato particolare. La proprietà fornisce solo informazioni di base sullo stato dell'elemento e può essere utilizzata, ad esempio, per stabilire se l'elemento è stato scelto, è selezionato o è attivo. Per ottenere maggiori informazioni, recuperare l'elemento tramite la proprietà Item e verificarne direttamente le proprietà.

Nell'esempio di codice riportato di seguito viene illustrato l'utilizzo della proprietà State in un'applicazione che fornisce la creazione personalizzata per un controllo ListView. Nell'esempio, in un gestore per l'evento ListView.DrawItem viene creato lo sfondo per interi elementi. In tutte le visualizzazioni tranne Dettagli, questo gestore crea anche il testo in primo piano. In visualizzazione Dettagli, il testo in primo piano viene creato nell'evento ListView.DrawSubItem.

Per l'esempio completo, vedere l'argomento relativo ai cenni preliminari su DrawListViewItemEventArgs.

// 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 the column header row and for entire
// ListView items.
private void myListView_DrawItem(Object sender, DrawListViewItemEventArgs e)
{
    // Draw the background for the column header row.
    if (e.get_ItemIndex() == -1) {
        e.get_Item().set_BackColor(Color.get_Black());
        e.DrawBackground();
    }
    // Draw the background for a selected item.
    else {
        if (Convert.ToInt32((e.get_State() & ListViewItemStates.Selected))
            != 0) {
            e.get_Graphics().FillRectangle(Brushes.get_Maroon(),
                e.get_Bounds());
            e.DrawFocusRectangle();
        }
        // Draw the background for an unselected item.
        else {
            LinearGradientBrush myBrush = new LinearGradientBrush(
                e.get_Bounds(), Color.get_Orange(), Color.get_Maroon(),
                LinearGradientMode.Horizontal);
            try {
                e.get_Graphics().FillRectangle(myBrush, e.get_Bounds());
            }
            finally {
                myBrush.Dispose();
            }    
        }
    }
    // Draw the item text for views other than the Details view.
    if (!(((ListView)sender).get_View().Equals(View.Details))) {
        e.DrawText();
    }
} //myListView_DrawItem

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile per Pocket PC, Windows Mobile per Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

Microsoft .NET Framework 3.0 è supportato in Windows Vista, Microsoft Windows XP SP2 e Windows Server 2003 SP1.

.NET Framework

Supportato in:
Il documento è risultato utile?
(1500 caratteri rimanenti)

Aggiunte alla community

AGGIUNGI
© 2013 Microsoft. Tutti i diritti riservati.