DrawListViewItemEventArgs.DrawFocusRectangle Metoda

Definice

Nakreslí obdélník fokusu pro objekt, ListViewItem pokud má fokus.

public:
 void DrawFocusRectangle();
public void DrawFocusRectangle ();
member this.DrawFocusRectangle : unit -> unit
Public Sub DrawFocusRectangle ()

Příklady

Následující příklad kódu ukazuje, jak použít metodu DrawFocusRectangle v aplikaci, která poskytuje vlastní výkres pro ovládací prvek ListView . V příkladu obslužná rutina ListView.DrawItem události vykreslí pozadí pro celé položky. Ve všech zobrazeních kromě zobrazení podrobností tato obslužná rutina také nakreslí text na popředí. V zobrazení podrobností se text na popředí vykreslí v ListView.DrawSubItem události.

Úplný příklad najdete v tématu s referenčními informacemi k přehledu 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

Poznámky

Pomocí této metody můžete nakreslit obdélník standardního fokusu kolem položky. Obdélník fokusu se obvykle nakreslí v oblasti určené Bounds vlastností . Pokud je ovládací prvek v zobrazení podrobností a ListView.FullRowSelect hodnota vlastnosti je false, je však obdélník fokusu nakreslen kolem výchozí textové oblasti pro první sloupec položky.

Obdélník fokusu je nakreslen pouze v případě, že má položka fokus, takže před voláním této metody nemusíte kontrolovat stav fokusu položky.

Platí pro

Viz také