ListViewItemStates 枚举

定义

定义表示 ListViewItem可能状态的常量。

此枚举支持其成员值的按位组合。

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

字段

名称 说明
Selected 1

选择此项。

Grayed 2

该项目处于禁用状态。

Checked 8

已选中该项。

Focused 16

该项具有焦点。

Default 32

该项处于其默认状态。

Hot 64

该项当前位于鼠标指针下。

Marked 128

项目已标记。

Indeterminate 256

该项处于不确定状态。

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

注解

此枚举由 DrawListViewItemEventArgs.State 属性 DrawListViewSubItemEventArgs.ItemState 使用。 有关详细信息,请参阅和ListView.DrawItemListView.DrawSubItem事件。

适用于

另请参阅