ListViewItemStates 列舉
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
定義常數,表示 ListViewItem的可能狀態。
此列舉支援其成員值的位元組合。
public enum class ListViewItemStates
[System.Flags]
public enum ListViewItemStates
[<System.Flags>]
type ListViewItemStates =
Public Enum ListViewItemStates
- 繼承
- 屬性
欄位
| 名稱 | 值 | Description |
|---|---|---|
| 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.DrawItem活動。ListView.DrawSubItem