Glyph.GetHitTest Method (Point)

 
System_CAPS_noteNote

The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Provides hit test logic.

Namespace:   System.Windows.Forms.Design.Behavior
Assembly:  System.Design (in System.Design.dll)

public abstract Cursor GetHitTest(
	Point p
)

Parameters

p
Type: System.Drawing.Point

A point to hit-test.

Return Value

Type: System.Windows.Forms.Cursor

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

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.

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

.NET Framework
Available since 2.0
Return to top
Show: