Freigeben über


Ink.HitTest Method

Ink.HitTest Method

Returns the Strokes collection of Stroke objects that are either completely inside or intersected by a known circle.

Definition

Visual Basic .NET Public Function HitTest( _
ByVal point As Point, _
ByVal radius As Single _
) As Strokes
C# public Strokes HitTest(
Point point,
float radius
);
Managed C++ public: Strokes* HitTest(
Point *point,
float *radius
);

Parameters

point System.Drawing.Point. The center of the hit test circle, in ink space coordinates.
radius System.Single. The radius of the hit test circle, in ink space coordinates.

Return Value

Microsoft.Ink.Strokes. Returns the Strokes collection contained within the specified area.

Exceptions

ObjectDisposedException Leave Site: The Ink object is disposed.

Remarks

If a Stroke object intersects the circle, the complete Stroke is returned.

This method computes the intersection, considering the full set of DrawingAttributes that apply to the Stroke object, including the Width, whether the FitToCurve property is true or false, and the value of the PenTip property.

After a rotation or shear transform has been performed on a Stroke object or a Strokes collection, the transformed x and y coordinates are no longer concentric with the original coordinates. Because of this, the radius parameter should not be calculated from the x or y coordinates.

To determine which points of a known Stroke object intersect the hit test area, call the Stroke.HitTest method.

Examples

[C#]

This C# example uses the HitTest method to determine if any Stroke objects of an Ink object are within a known radius of a point. The point parameter is specified in pixels, and the radius parameter is specified in ink space coordinates.

private bool PerformHitTest(
    System.Drawing.Graphics g,
    Microsoft.Ink.InkCollector theInkCollector,
    System.Drawing.Point thePoint,
    int radius,
    Microsoft.Ink.Ink theInk)
{
    // Convert point to ink space coordinates
    theInkCollector.Renderer.PixelToInkSpace(g, ref thePoint);

    // Find strokes hit by the circle described by thePoint and radius
    Microsoft.Ink.Strokes hitStrokes = theInk.HitTest(thePoint, radius);

    // Return true if any strokes were hit
    return (hitStrokes.Count > 0);
}

[Visual Basic .NET]

This Microsoft® Visual Basic® .NET example uses the HitTest method to determine if any Stroke objects of an Ink object are within a known radius of a point. The point parameter is specified in pixels, and the radius parameter is specified in ink space coordinates.

Function PerformHitTest( _
    ByRef g As System.Drawing.Graphics, _
    ByRef theInkCollector As Microsoft.Ink.InkCollector, _
    ByRef thePoint As System.Drawing.Point, _
    ByVal radius As Integer, _
    ByRef theInk As Microsoft.Ink.Ink _
) As Boolean
    Dim hitStrokes As Microsoft.Ink.Strokes

    ' Convert point to ink space coordinates
    theInkCollector.Renderer.PixelToInkSpace(g, thePoint)

    ' Find strokes hit by the circle described by thePoint and radius
    hitStrokes = theInk.HitTest(thePoint, radius)

    ' Return true if any strokes were hit
    Return (hitStrokes.Count > 0)
End Function

See Also