共用方式為


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 方法。

適用於

另請參閱