DrawListViewItemEventArgs.State 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
取得目前的狀態 ListViewItem 來繪製。
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
屬性值
一個位元組合 ListViewItemStates 的值,表示當前狀態 ListViewItem。
範例
以下程式碼範例示範如何在提供自訂控制圖ListView的應用程式中使用該State屬性。 在這個例子中,事件的處理器 ListView.DrawItem 會為整個項目繪製背景。 除了細節檢視外,所有檢視中,這個處理器同時繪製前景文字。 在細節檢視中,前景文字會繪製在事件中 ListView.DrawSubItem 。
完整範例請參閱 DrawListViewItemEventArgs 概述參考主題。
// 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
備註
利用此特性檢查圖繪是否 ListViewItem 處於特定狀態。 此特性僅提供物品的基本狀態資訊。 例如,你可以利用這個特性來判斷某個項目是否被選取、勾選或聚焦。 如果你需要更多了解,可以透過該 Item 物業檢索物品並直接檢查其屬性。