DrawListViewItemEventArgs.State プロパティ

定義

描画する 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 値のビットごとの組み合わせ。

次のコード例では、コントロールのカスタム描画を State 提供するアプリケーションで プロパティを使用する方法を ListView 示します。 この例では、 イベントのハンドラーによって 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取得し、そのプロパティを直接チェックします。

適用対象

こちらもご覧ください