Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Glyph.GetHitTest Method

Provides hit test logic.

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

public abstract Cursor GetHitTest(
	Point 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

Supported in: 4.6, 4.5, 4, 3.5, 3.0, 2.0
© 2015 Microsoft