Edit

Share via


Glyph.GetHitTest(Point) Method

Definition

Provides hit test logic.

public abstract System.Windows.Forms.Cursor GetHitTest(System.Drawing.Point p);
public abstract System.Windows.Forms.Cursor? GetHitTest(System.Drawing.Point p);

Parameters

p
Point

A point to hit-test.

Returns

A Cursor if the Glyph is associated with p; otherwise, null.

Examples

The following example demonstrates how to override the GetHitTest to see if the point is within this glyph. This code example is part of a larger example provided for the BehaviorService class.

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;
}

Remarks

The GetHitTest method is an abstract method that forces Glyph implementations to provide hit test logic. Given any point, if the Glyph has decided to be involved with that location, it will need to return a valid Cursor. Otherwise, returning null will cause the BehaviorService to ignore the location.

Applies to

Product Versions
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

See also