Stroke.HitTest Stroke.HitTest Stroke.HitTest Stroke.HitTest Method

Definition

Returns whether the Stroke intersects or is within a certain area.

Overloads

HitTest(Point) HitTest(Point) HitTest(Point)

Returns a value that indicates whether current Stroke intersects the specified point.

HitTest(IEnumerable<Point>, Int32) HitTest(IEnumerable<Point>, Int32) HitTest(IEnumerable<Point>, Int32) HitTest(IEnumerable<Point>, Int32)

Returns a value that indicates whether the current Stroke is within the specified bounds.

HitTest(IEnumerable<Point>, StylusShape) HitTest(IEnumerable<Point>, StylusShape) HitTest(IEnumerable<Point>, StylusShape)

Returns whether the specified path intersects the Stroke using the specified StylusShape.

HitTest(Point, Double) HitTest(Point, Double) HitTest(Point, Double)

Returns a value that indicates whether current Stroke intersects the specified area.

HitTest(Rect, Int32) HitTest(Rect, Int32) HitTest(Rect, Int32) HitTest(Rect, Int32)

Returns a value that indicates whether the Stroke is within the bounds of the specified rectangle.

Remarks

You can use the HitTest methods to determine whether a Stroke intersects a certain point or is within specified bounds.

The following methods check whether the Stroke is intersected.

The following methods check whether the Stroke is surrounded.

HitTest(Point) HitTest(Point) HitTest(Point)

Returns a value that indicates whether current Stroke intersects the specified point.

public:
 bool HitTest(System::Windows::Point point);
public bool HitTest (System.Windows.Point point);
member this.HitTest : System.Windows.Point -> bool

Parameters

point
Point Point Point Point

The Point to hit test.

Returns

true if point intersects the current stroke; otherwise, false.

Examples

The following example changes the color of a Stroke if it intersects a certain area.

Point myPoint = new Point(100, 100);

if (myStroke.HitTest(myPoint, 10))
{
    myStroke.DrawingAttributes.Color = Colors.Red;
}
Dim myPoint As New System.Windows.Point(100, 100)

If myStroke.HitTest(myPoint, 10) Then
    myStroke.DrawingAttributes.Color = Colors.Red
End If

Remarks

This method behaves the same way as the overloaded HitTest(Point, Double) method does when diameter is 1.

HitTest(IEnumerable<Point>, Int32) HitTest(IEnumerable<Point>, Int32) HitTest(IEnumerable<Point>, Int32) HitTest(IEnumerable<Point>, Int32)

Returns a value that indicates whether the current Stroke is within the specified bounds.

public:
 bool HitTest(System::Collections::Generic::IEnumerable<System::Windows::Point> ^ lassoPoints, int percentageWithinLasso);
public bool HitTest (System.Collections.Generic.IEnumerable<System.Windows.Point> lassoPoints, int percentageWithinLasso);
member this.HitTest : seq<System.Windows.Point> * int -> bool
Public Function HitTest (lassoPoints As IEnumerable(Of Point), percentageWithinLasso As Integer) As Boolean

Parameters

lassoPoints
IEnumerable<Point>

An array of type Point that represents the bounds of the area to hit test.

percentageWithinLasso
Int32 Int32 Int32 Int32

The percentage of the length of the Stroke, that must be in lassoPoints for the Stroke to be considered hit.

Returns

true if the current stroke is within the specified bounds; otherwise false.

Examples

The following example renders a stroke purple if at least 80% of the stroke is within the bounds of myPoints.

Point[] myPoints = new Point[] {
    new Point(100, 100),
    new Point(200, 100),
    new Point(200, 200),
    new Point(100, 200)};

if (aStroke.HitTest(myPoints, 80))
{
    aStroke.DrawingAttributes.Color = Colors.Purple;
}
Dim myPoints() As System.Windows.Point = _
                      {New System.Windows.Point(100, 100), _
                       New System.Windows.Point(200, 100), _
                       New System.Windows.Point(200, 200), _
                       New System.Windows.Point(100, 200)}

If aStroke.HitTest(myPoints, 80) Then
    aStroke.DrawingAttributes.Color = Colors.Purple
End If

Remarks

The HitTest method connects the first and last points in lassoPoints to create the lasso.

HitTest(IEnumerable<Point>, StylusShape) HitTest(IEnumerable<Point>, StylusShape) HitTest(IEnumerable<Point>, StylusShape)

Returns whether the specified path intersects the Stroke using the specified StylusShape.

public:
 bool HitTest(System::Collections::Generic::IEnumerable<System::Windows::Point> ^ path, System::Windows::Ink::StylusShape ^ stylusShape);
public bool HitTest (System.Collections.Generic.IEnumerable<System.Windows.Point> path, System.Windows.Ink.StylusShape stylusShape);
member this.HitTest : seq<System.Windows.Point> * System.Windows.Ink.StylusShape -> bool

Parameters

path
IEnumerable<Point>

The path that stylusShape follows for hit testing

stylusShape
StylusShape StylusShape StylusShape StylusShape

The shape of path with which to hit test.

Returns

true if stylusShape intersects the current stroke; otherwise, false.

Examples

The following code renders a stroke purple if the stroke intersects the path of myPoints.

Point[] myPoints = new Point[] {
    new Point(100, 100),
    new	Point(200, 100),
    new	Point(200, 200),
    new	Point(100, 200)};

EllipseStylusShape myStylus = new EllipseStylusShape(5.0, 5.0, 0.0);

if (aStroke.HitTest(myPoints, myStylus))
{
    aStroke.DrawingAttributes.Color = Colors.Purple;
}
Dim myPoints() As System.Windows.Point = _
                      {New System.Windows.Point(100, 100), _
                       New System.Windows.Point(200, 100), _
                       New System.Windows.Point(200, 200), _
                       New System.Windows.Point(100, 200)}

Dim myStylus As New EllipseStylusShape(5.0, 5.0, 0.0)

If aStroke.HitTest(myPoints, myStylus) Then
    aStroke.DrawingAttributes.Color = Colors.Purple
End If

Remarks

The HitTest method uses stylusShape to hit test the stroke along eraserPath.

HitTest(Point, Double) HitTest(Point, Double) HitTest(Point, Double)

Returns a value that indicates whether current Stroke intersects the specified area.

public:
 bool HitTest(System::Windows::Point point, double diameter);
public bool HitTest (System.Windows.Point point, double diameter);
member this.HitTest : System.Windows.Point * double -> bool

Parameters

point
Point Point Point Point

The Point that defines the center of the area to hit test.

diameter
Double Double Double Double

The diameter of the area to hit test.

Returns

true if the specified area intersects the current stroke; otherwise, false.

Examples

The following example changes the color of a Stroke if it intersects a certain area.

Point myPoint = new Point(100, 100);

if (myStroke.HitTest(myPoint, 10))
{
    myStroke.DrawingAttributes.Color = Colors.Red;
}
Dim myPoint As New System.Windows.Point(100, 100)

If myStroke.HitTest(myPoint, 10) Then
    myStroke.DrawingAttributes.Color = Colors.Red
End If

HitTest(Rect, Int32) HitTest(Rect, Int32) HitTest(Rect, Int32) HitTest(Rect, Int32)

Returns a value that indicates whether the Stroke is within the bounds of the specified rectangle.

public:
 bool HitTest(System::Windows::Rect bounds, int percentageWithinBounds);
public bool HitTest (System.Windows.Rect bounds, int percentageWithinBounds);
member this.HitTest : System.Windows.Rect * int -> bool
Public Function HitTest (bounds As Rect, percentageWithinBounds As Integer) As Boolean

Parameters

bounds
Rect Rect Rect Rect

A Rect that represents the bounds of the area to hit test.

percentageWithinBounds
Int32 Int32 Int32 Int32

The percentage of the length of the Stroke, that must be in percentageWithinBounds for the Stroke to be considered hit.

Returns

true if the current stroke is within the bounds of bounds; otherwise, false.

Examples

The following example renders a stroke purple if at least 80% of the stroke is within the Rect.

Rect rect1 = new Rect(100, 100, 100, 100);

if (aStroke.HitTest(rect1, 80))
{
    aStroke.DrawingAttributes.Color = Colors.Purple;
}
Dim rect1 As New Rect(100, 100, 100, 100)

If aStroke.HitTest(rect1, 80) Then
    aStroke.DrawingAttributes.Color = Colors.Purple
End If

Applies to