Sdílet prostřednictvím


DrawListViewItemEventArgs.Item Vlastnost

Definice

ListViewItem Získá kreslit.

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

Hodnota vlastnosti

Nakreslení ListViewItem .

Příklady

Následující příklad kódu ukazuje, jak použít Item vlastnost v aplikaci, která poskytuje vlastní výkres ListView ovládacího prvku. V příkladu obslužná rutina události ListView.DrawItem nakreslí pozadí pro celé položky. Ve všechzobrazeních V zobrazení podrobností je text popředí vykreslen v ListView.DrawSubItem události.

Úplný příklad najdete v referenčním tématu přehledu 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

Poznámky

Tato vlastnost slouží pro přístup ListViewItem k kreslení. To je užitečné, když State vlastnost neposkytuje adekvátní informace pro splnění vašich potřeb. Vlastnost State poskytuje pouze základní informace o stavu, které můžete použít, například k určení, zda je položka vybrána, zaškrtnuto nebo zaměřena. Naproti Item tomu vlastnost umožňuje přístup ke všem členům ListViewItem. K položce musíte přistupovat přímo, například pokud chcete nakreslit ListViewItem.Text hodnotu sami, a ne použít metodu DrawText .

Platí pro

Viz také