DrawListViewItemEventArgs.Bounds プロパティ

定義

描画する ListViewItem のサイズと位置を取得します。

public:
 property System::Drawing::Rectangle Bounds { System::Drawing::Rectangle get(); };
public System.Drawing.Rectangle Bounds { get; }
member this.Bounds : System.Drawing.Rectangle
Public ReadOnly Property Bounds As Rectangle

プロパティ値

描画する Rectangle の境界を表す ListViewItem

次のコード例では、コントロールのカスタム描画を Bounds 提供するアプリケーションで プロパティを使用する方法を 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

注釈

このプロパティで指定された場所は、コントロールの ListView 左上隅からの相対位置です。

の特定の部分の境界を ListViewItem取得するには、 メソッドを使用します ListViewItem.GetBounds

適用対象

こちらもご覧ください