DrawListViewItemEventArgs.State Właściwość

Definicja

Pobiera bieżący stan ListViewItem do rysowania.

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

Wartość właściwości

Bitowa kombinacja ListViewItemStates wartości wskazująca bieżący stan .ListViewItem

Przykłady

W poniższym przykładzie kodu pokazano, jak używać State właściwości w aplikacji, która udostępnia niestandardowy rysunek dla kontrolki ListView . W tym przykładzie program obsługi zdarzenia ListView.DrawItem rysuje tło dla całych elementów. We wszystkich widokach oprócz widoku szczegółów ta procedura obsługi rysuje również tekst pierwszego planu. W widoku szczegółów tekst pierwszego planu jest rysowany w ListView.DrawSubItem zdarzeniu.

Pełny przykład można znaleźć w temacie referencyjnym DrawListViewItemEventArgs przeglądu.

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

Uwagi

Użyj tej właściwości, aby sprawdzić, czy rysowanie ListViewItem ma określony stan. Ta właściwość zawiera tylko podstawowe informacje o stanie elementu. Możesz na przykład użyć tej właściwości, aby określić, czy element jest zaznaczony, zaznaczony, czy ukierunkowany. Jeśli chcesz dowiedzieć się więcej, pobierz element za pośrednictwem Item właściwości i sprawdź jego właściwości bezpośrednio.

Dotyczy

Zobacz też