Udostępnij za pośrednictwem


Glyph.GetHitTest(Point) Metoda

Definicja

Zapewnia logikę testu trafień.

public:
 abstract System::Windows::Forms::Cursor ^ GetHitTest(System::Drawing::Point p);
public abstract System.Windows.Forms.Cursor GetHitTest (System.Drawing.Point p);
public abstract System.Windows.Forms.Cursor? GetHitTest (System.Drawing.Point p);
abstract member GetHitTest : System.Drawing.Point -> System.Windows.Forms.Cursor
Public MustOverride Function GetHitTest (p As Point) As Cursor

Parametry

p
Point

Punkt na test trafienia.

Zwraca

A Cursor jeśli element Glyph jest skojarzony z elementem p; w przeciwnym razie null.

Przykłady

W poniższym przykładzie pokazano, jak zastąpić metodę GetHitTest , aby sprawdzić, czy punkt znajduje się w tym glyph. Ten przykład kodu jest częścią większego przykładu podanego BehaviorService dla klasy.

public:
    virtual Cursor^ GetHitTest(Point p) override
    {
        // GetHitTest is called to see if the point is
        // within this glyph.  This gives us a chance to decide
        // what cursor to show.  Returning null from here means
        // the mouse pointer is not currently inside of the
        // glyph.  Returning a valid cursor here indicates the
        // pointer is inside the glyph, and also enables our
        // Behavior property as the active behavior.
        if (Bounds.Contains(p))
        {
            return Cursors::Hand;
        }
        return nullptr;
    }
public override Cursor GetHitTest(Point p)
{
    // GetHitTest is called to see if the point is
    // within this glyph.  This gives us a chance to decide
    // what cursor to show.  Returning null from here means
    // the mouse pointer is not currently inside of the glyph.
    // Returning a valid cursor here indicates the pointer is
    // inside the glyph, and also enables our Behavior property
    // as the active behavior.
    if (Bounds.Contains(p))
    {
        return Cursors.Hand;
    }

    return null;
}
Public Overrides Function GetHitTest(ByVal p As Point) As Cursor
    ' GetHitTest is called to see if the point is
    ' within this glyph.  This gives us a chance to decide
    ' what cursor to show.  Returning null from here means
    ' the mouse pointer is not currently inside of the glyph.
    ' Returning a valid cursor here indicates the pointer is
    ' inside the glyph,and also enables our Behavior property
    ' as the active behavior.
    If Bounds.Contains(p) Then
        Return Cursors.Hand
    End If

    Return Nothing

End Function

Uwagi

Metoda GetHitTest jest abstract metodą, która wymusza Glyph implementacje w celu zapewnienia logiki testu trafienia. Biorąc pod uwagę dowolny punkt, jeśli Glyph użytkownik zdecydował się być zaangażowany w daną lokalizację, będzie musiał zwrócić prawidłowy Cursorelement . W przeciwnym razie zwracanie spowoduje BehaviorService zignorowanie null lokalizacji.

Dotyczy

Zobacz też