ListViewItemStates 列舉

定義

定義表示 ListViewItem 可能狀態的常數。

此列舉支援其成員值的位元組合。

public enum class ListViewItemStates
[System.Flags]
public enum ListViewItemStates
[<System.Flags>]
type ListViewItemStates = 
Public Enum ListViewItemStates
繼承
ListViewItemStates
屬性

欄位

Checked 8

已選取這個項目。

Default 32

這個項目處於預設狀態。

Focused 16

項目已取得焦點。

Grayed 2

項目已停用。

Hot 64

項目目前位在滑鼠指標之下。

Indeterminate 256

項目處於未定狀態。

Marked 128

這個項目已標示。

Selected 1

這個項目已選取。

ShowKeyboardCues 512

項目應指示鍵盤快速鍵。

範例

下列範例示範如何為 ListView 控制項提供自訂繪圖。 範例 ListView 中的 控制項具有漸層背景。 負值的子專案具有紅色前景和黑色背景。

事件的處理常式 ListView.DrawItem 會繪製整個專案的背景,以及資料行標頭資料列的背景。 事件的處理常式 ListView.DrawSubItem 會繪製文字值,以及具有負值的子專案的文字和背景。

ContextMenu元件提供在詳細資料檢視與清單之間切換的方法。 在清單檢視中,只會 ListView.DrawItem 引發 事件。 在此情況下,會在事件處理常式中 ListView.DrawItem 繪製文字和背景。

如需完整的範例,請參閱 ListView.OwnerDraw 參考主題。

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

備註

DrawListViewSubItemEventArgs.ItemState 屬性會 DrawListViewItemEventArgs.State 使用此列舉。 如需詳細資訊,請參閱 ListView.DrawItemListView.DrawSubItem 事件。

適用於

另請參閱