Share via


Ink.HitTest Method (array<Point[], Single)

Returns the Strokes collection contained within a polyline selection boundary.

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

Syntax

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

returnValue = instance.HitTest(points, _
    percentIntersect)
public Strokes HitTest(
    Point[] points,
    float percentIntersect
)
public:
Strokes^ HitTest(
    array<Point>^ points, 
    float percentIntersect
)
public function HitTest(
    points : Point[], 
    percentIntersect : float
) : Strokes

Parameters

  • points
    Type: array<System.Drawing.Point[]

    The points that are used in the selection boundary to select the Stroke objects. The selection area is the area inside the selection boundary in which the boundary first intersects itself.

  • percentIntersect
    Type: System.Single

    Percentage of points in the Stroke which must be contained in the selection boundary to be considered a hit.

Return Value

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

Remarks

If the selection boundary does not intersect itself, the HitTest method adds a point to the end of the array to create a straight line from the first point to the last point. If the boundary is a straight line with no area within the selection boundary, no Stroke objects are selected.

This method throws an exception if the points parameter is nulla null reference (Nothing in Visual Basic) (Nothing in Microsoft Visual Basic.NET) or contains fewer than three points.

Examples

In this example, any Stroke objects of an InkOverlay that have at least 50% of their points inside a boundary selection are changed to red. The boundary selection points describe a rectangle that is rotated 45 degrees around the center of the ink control. The boundary selection is made visible by using the selection points to create a Stroke object.

Const RadiusPixel As Integer = 120
' get the control. InkOverlay.AttachedControl must be set 
Dim inkControl As Control = mInkOverlay.AttachedControl
' get the center of the ink control 
Dim centerPt As Point = New Point(inkControl.Width / 2, inkControl.Height / 2)
' create the boundary points. These points describe a rectangle 
' that is rotated around the center 45 degrees (a diamond) 
Dim boundaryPts() As Point = _
        { _
            New Point(centerPt.X, centerPt.Y - (RadiusPixel / 2)), _
            New Point(centerPt.X + (RadiusPixel / 2), centerPt.Y), _
            New Point(centerPt.X, centerPt.Y + (RadiusPixel / 2)), _
            New Point(centerPt.X - (RadiusPixel / 2), centerPt.Y), _
            New Point(centerPt.X, centerPt.Y - (RadiusPixel / 2)) _
        }

Using g As Graphics = inkControl.CreateGraphics()
    ' convert boundary points to ink space coordinates
    mInkOverlay.Renderer.PixelToInkSpace(g, boundaryPts)
End Using 
' show the tilted rectangle (diamond) by creating a stroke
mInkOverlay.Ink.CreateStroke(boundaryPts)
' Find strokes that are at least 50% inside the boundary points 
Dim hitStrokes As Strokes = mInkOverlay.Ink.HitTest(boundaryPts, 50.0F)
' change the strokes that fall inside the boundary points to red
hitStrokes.ModifyDrawingAttributes(New DrawingAttributes(Color.Red))
' invalidate the ink control
inkControl.Invalidate()
const int RadiusPixel = 120;
// get the control. InkOverlay.AttachedControl must be set
Control inkControl = mInkOverlay.AttachedControl;
// get the center of the ink control
Point centerPt = new Point(inkControl.Width / 2, inkControl.Height / 2);
// create the boundary points. These points describe a rectangle 
// that is rotated around the center 45 degrees (a diamond)
Point[] boundaryPts = new Point[5] 
    {
        new Point(centerPt.X, centerPt.Y - (RadiusPixel / 2)),
        new Point(centerPt.X + (RadiusPixel / 2), centerPt.Y),
        new Point(centerPt.X, centerPt.Y + (RadiusPixel / 2)),
        new Point(centerPt.X - (RadiusPixel / 2), centerPt.Y),
        new Point(centerPt.X, centerPt.Y - (RadiusPixel / 2))
    };

using (Graphics g = inkControl.CreateGraphics())
{
    // convert boundary points to ink space coordinates
    mInkOverlay.Renderer.PixelToInkSpace(g, ref boundaryPts);
}

// show the tilted rectangle (diamond) by creating a stroke
mInkOverlay.Ink.CreateStroke(boundaryPts);
// Find strokes that are at least 50% inside the boundary points
Strokes hitStrokes = mInkOverlay.Ink.HitTest(boundaryPts, 50.0f);
// change the strokes that fall inside the boundary points 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