Bagikan melalui


DrawListViewItemEventArgs.State Properti

Definisi

Mendapatkan status ListViewItem gambar saat ini.

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

Nilai Properti

Kombinasi bitwise dari ListViewItemStates nilai yang menunjukkan status saat ini dari ListViewItem.

Contoh

Contoh kode berikut menunjukkan cara menggunakan State properti dalam aplikasi yang menyediakan gambar kustom untuk ListView kontrol. Dalam contoh, handler untuk ListView.DrawItem peristiwa menggambar latar belakang untuk seluruh item. Di semua tampilan kecuali tampilan detail, handler ini juga menggambar teks latar depan. Dalam tampilan detail, teks latar depan digambar dalam peristiwa tersebut ListView.DrawSubItem .

Untuk contoh lengkapnya, lihat DrawListViewItemEventArgs topik referensi gambaran umum.

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

Keterangan

Gunakan properti ini untuk memeriksa apakah gambar ListViewItem dalam keadaan tertentu. Properti ini hanya menyediakan informasi status dasar tentang item. Anda dapat menggunakan properti ini, misalnya, untuk menentukan apakah item dipilih, dicentang, atau difokuskan. Jika Anda perlu mengetahui lebih lanjut, ambil item melalui Item properti dan periksa propertinya secara langsung.

Berlaku untuk

Lihat juga