다음을 통해 공유


DrawListViewItemEventArgs.Item 속성

정의

그릴 값을 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 그릴 것입니다.

예제

다음 코드 예제에서는 컨트롤에 ItemListView 한 사용자 지정 그리기를 제공 하는 애플리케이션에서 속성을 사용 하는 방법을 보여 줍니다. 이 예제에서 이벤트에 대한 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.TextDrawText 직접 액세스해야 합니다.

적용 대상

추가 정보