DrawListViewItemEventArgs.Bounds Własność
Definicja
Ważny
Niektóre informacje dotyczą produktów przedpremierowych, które mogą zostać znacznie zmodyfikowane przed premierą. Microsoft nie udziela żadnych gwarancji, ani wyraźnych, ani domniemanych, dotyczących informacji podanych tutaj.
Pobiera rozmiar i lokalizację ListViewItem obiektu do rysowania.
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
Wartość nieruchomości
Obiekt Rectangle reprezentujący granice ListViewItem obiektu do rysowania.
Przykłady
W poniższym przykładzie kodu pokazano, jak używać Bounds właściwości w aplikacji, która udostępnia niestandardowy rysunek dla kontrolki ListView . W tym przykładzie program obsługi zdarzenia ListView.DrawItem rysuje tło dla całych elementów. We wszystkich widokach oprócz widoku szczegółów ta procedura obsługi rysuje również tekst pierwszego planu. W widoku szczegółów tekst pierwszego planu jest rysowany w ListView.DrawSubItem zdarzeniu.
Pełny przykład można znaleźć w temacie referencyjnym DrawListViewItemEventArgs przeglądu.
// 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
Uwagi
Lokalizacja określona przez tę właściwość jest względna w lewym górnym rogu kontrolki ListView .
Aby pobrać granice dla określonych części obiektu ListViewItem, użyj ListViewItem.GetBounds metody .