Share via


Ink.HitTest Method (Rectangle, Single)

Returns the Strokes collection contained within a known Rectangle.

Namespace:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Syntax

'Declaration
Public Function HitTest ( _
    selectionRectangle As Rectangle, _
    percentIntersect As Single _
) As Strokes
'Usage
Dim instance As Ink 
Dim selectionRectangle As Rectangle 
Dim percentIntersect As Single 
Dim returnValue As Strokes 

returnValue = instance.HitTest(selectionRectangle, _
    percentIntersect)
public Strokes HitTest(
    Rectangle selectionRectangle,
    float percentIntersect
)
public:
Strokes^ HitTest(
    Rectangle selectionRectangle, 
    float percentIntersect
)
public function HitTest(
    selectionRectangle : Rectangle, 
    percentIntersect : float
) : Strokes

Parameters

  • percentIntersect
    Type: System.Single

    The percentage value that determines which Stroke objects are included in the Strokes collection. Stroke objects that intersect the rectangle are included in the Strokes collection if the percentage of points in those Stroke objects contained within the rectangle is greater than or equal to the percentage passed in to the percentIntersect parameter.

Return Value

Type: Microsoft.Ink.Strokes
The Strokes collection contained within the specified area.

Remarks

To determine which points of a known Stroke object intersect the hit test area, call the Stroke.GetRectangleIntersections method, which returns the points where a Stroke object intersects a known Rectangle.

Examples

In this example, any Stroke objects of an InkOverlay that have at least 75% of their points inside a rectangle as defined by the upper left 2000 x 2000 HIMETRIC units of the ink control are changed to red. The rectangle is made visible by using the selection points to create a Stroke object.

Const RectSideInkUnits As Integer = 2000
' get the control. InkOverlay.AttachedControl must be set 
Dim inkControl As Control = mInkOverlay.AttachedControl
' create the rectangle used for the hit test 
Dim hitTestRect As Rectangle = New Rectangle(0, 0, RectSideInkUnits, RectSideInkUnits)
' create boundary points in order to show the rectangle by creating a stroke 
Dim boundaryPts() As Point = _
    { _
        New Point(RectSideInkUnits, 0), _
        New Point(RectSideInkUnits, RectSideInkUnits), _
        New Point(0, RectSideInkUnits) _
    }

' show the rectangle by creating a stroke
mInkOverlay.Ink.CreateStroke(boundaryPts)
' Find strokes that fall at least 75% within the rectangle 
Dim hitStrokes As Strokes = mInkOverlay.Ink.HitTest(hitTestRect, 75.0F)
' change the found strokes to red
hitStrokes.ModifyDrawingAttributes(New DrawingAttributes(Color.Red))
' invalidate the ink control
inkControl.Invalidate()
const int RectSideInkUnits = 2000;
// get the control. InkOverlay.AttachedControl must be set
Control inkControl = mInkOverlay.AttachedControl;
// create the rectangle used for the hit test
Rectangle hitTestRect = new Rectangle(0, 0, RectSideInkUnits, RectSideInkUnits);
// create boundary points in order to show the rectangle by creating a stroke
Point[] boundaryPts = new Point[3] 
    {
        new Point(RectSideInkUnits, 0),
        new Point(RectSideInkUnits, RectSideInkUnits),
        new Point(0, RectSideInkUnits)
    };

// show the rectangle by creating a stroke
mInkOverlay.Ink.CreateStroke(boundaryPts);
// Find strokes that fall at least 75% within the rectangle
Strokes hitStrokes = mInkOverlay.Ink.HitTest(hitTestRect, 75.0f);
// change the found strokes to red
hitStrokes.ModifyDrawingAttributes(new DrawingAttributes(Color.Red));
// invalidate the ink control
inkControl.Invalidate();

Platforms

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

Ink Class

Ink Members

HitTest Overload

Microsoft.Ink Namespace

Strokes

ExtendedProperties