Share via


Ink.HitTest Method (Point, Single)

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

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

Syntax

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

returnValue = instance.HitTest(point, _
    radius)
public Strokes HitTest(
    Point point,
    float radius
)
public:
Strokes^ HitTest(
    Point point, 
    float radius
)
public function HitTest(
    point : Point, 
    radius : float
) : Strokes

Parameters

  • radius
    Type: System.Single

    The radius of the hit test circle, in ink space coordinates.

Return Value

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

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

In this example, any Stroke objects of an InkOverlay that intersect a circle with its center point in the middle of the ink control, and a radius of 120 pixels are changed to red. The circle that a Stroke must intersect to qualify for the color change is drawn in blue.

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 rectangle used to draw the circle around the center 
Dim hitTestRect As Rectangle = New Rectangle(centerPt.X - RadiusPixel, centerPt.Y - RadiusPixel, RadiusPixel * 2, RadiusPixel * 2)
' get our graphics object 
Dim g As Graphics = inkControl.CreateGraphics()
' convert centerPt to ink space coordinates
mInkOverlay.Renderer.PixelToInkSpace(g, centerPt)
' tempPt is used only to convert RadiusPixel to ink coords 
Dim tempPt As Point = New Point(RadiusPixel, 0)
mInkOverlay.Renderer.PixelToInkSpace(g, tempPt)
' now tempPt.X = radius in ink coordinates 
' Find strokes hit by the circle described by centerPt and radius 
Dim hitStrokes As Strokes = mInkOverlay.Ink.HitTest(centerPt, tempPt.X)
' change the strokes that fall inside the circle to red
hitStrokes.ModifyDrawingAttributes(New DrawingAttributes(Color.Red))
' invalidate the ink control
inkControl.Invalidate()
' let the Invalidate message process
Application.DoEvents()
' draw the circle we used for the hit test
g.DrawEllipse(Pens.Blue, hitTestRect)
g.Dispose()
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 rectangle used to draw the circle around the center
Rectangle hitTestRect = new Rectangle(centerPt.X - RadiusPixel, centerPt.Y - RadiusPixel, RadiusPixel * 2, RadiusPixel * 2);
// get our graphics object
Graphics g = inkControl.CreateGraphics();
// convert centerPt to ink space coordinates
mInkOverlay.Renderer.PixelToInkSpace(g, ref centerPt);
// tempPt is used only to convert RadiusPixel to ink coords
Point tempPt = new Point(RadiusPixel, 0);
mInkOverlay.Renderer.PixelToInkSpace(g, ref tempPt);
// now tempPt.X = radius in ink coordinates 
// Find strokes hit by the circle described by centerPt and radius
Strokes hitStrokes = mInkOverlay.Ink.HitTest(centerPt, tempPt.X);
// change the strokes that fall inside the circle to red
hitStrokes.ModifyDrawingAttributes(new DrawingAttributes(Color.Red));
// invalidate the ink control
inkControl.Invalidate();
// let the Invalidate message process
Application.DoEvents();
// draw the circle we used for the hit test
g.DrawEllipse(Pens.Blue, hitTestRect);
g.Dispose();

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