DrawListViewItemEventArgs.Item 屬性
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
他會畫 ListViewItem 畫。
public:
property System::Windows::Forms::ListViewItem ^ Item { System::Windows::Forms::ListViewItem ^ get(); };
public System.Windows.Forms.ListViewItem Item { get; }
member this.Item : System.Windows.Forms.ListViewItem
Public ReadOnly Property Item As ListViewItem
屬性值
畫 ListViewItem 畫。
範例
以下程式碼範例示範如何在提供自訂控制圖ListView的應用程式中使用該Item屬性。 在這個例子中,事件的處理器 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 圖繪圖。 當 State 房產無法提供足夠資訊以滿足你的需求時,這很有用。 該 State 屬性僅提供基本狀態資訊,例如可用來判斷項目是否被選取、檢查或聚焦。 而屬性 Item 則允許你存取所有成員 ListViewItem。 例如,您必須直接取得該物品,才能自行提取 ListViewItem.Text 價值,而非使用該 DrawText 方法。