StrokeCollection.HitTest Method

Definition

Returns a collection of strokes contained within the specified area.

Overloads

HitTest(Rect, Int32)

Returns a collection of strokes that have at least the specified percentage of length within the specified rectangle.

HitTest(Point, Double)

Returns a collection of strokes that intersect the specified area.

HitTest(IEnumerable<Point>, StylusShape)

Returns a collection of strokes that intersect with the specified path.

HitTest(IEnumerable<Point>, Int32)

Returns a collection of strokes that have at least the specified percentage of length within the specified area.

HitTest(Point)

Returns a collection of strokes that intersect the specified point.

HitTest(Rect, Int32)

Returns a collection of strokes that have at least the specified percentage of length within the specified rectangle.

C#
public System.Windows.Ink.StrokeCollection HitTest(System.Windows.Rect bounds, int percentageWithinBounds);

Parameters

bounds
Rect

A Rect that specifies the bounds to be hit tested.

percentageWithinBounds
Int32

The minimum required length of a Stroke that must exist within bounds for it to be considered hit.

Returns

A StrokeCollection that has strokes with at least the specified percentage within the Rect.

Examples

The following example erases the strokes that are at least 50% within the bounds of the Rect. This example assumes that there is an InkPresenter called presenter.

C#
Rect rect = new Rect(100, 100, 200, 200);
StrokeCollection strokes = presenter.Strokes.HitTest(rect, 50);

presenter.Strokes.Remove(strokes);

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

HitTest(Point, Double)

Returns a collection of strokes that intersect the specified area.

C#
public System.Windows.Ink.StrokeCollection HitTest(System.Windows.Point point, double diameter);

Parameters

point
Point

The Point to hit test.

diameter
Double

The size of the area around the Point to hit test.

Returns

A collection of Stroke objects that intersect the specified point.

Examples

The following example demonstrates how to get the strokes that intersect the specified Point. This example assumes that there is an InkPresenter called presenter.

C#
// Change the color of all the strokes at the specified position.
public void SelectStrokes(Point position)
{
    StrokeCollection selected = presenter.Strokes.HitTest(position, 5);

    foreach (Stroke s in selected)
    {
        s.DrawingAttributes.Color = Colors.Purple;
    }
}

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

HitTest(IEnumerable<Point>, StylusShape)

Returns a collection of strokes that intersect with the specified path.

C#
public System.Windows.Ink.StrokeCollection HitTest(System.Collections.Generic.IEnumerable<System.Windows.Point> path, System.Windows.Ink.StylusShape stylusShape);

Parameters

path
IEnumerable<Point>

An array to type Point that represents the path to be hit tested.

stylusShape
StylusShape

The StylusShape that specifies the shape of eraserPath.

Returns

A StrokeCollection of strokes that intersect with path.

Examples

The following example changes the color of all the strokes that intersect the path that is created by the Point array. This example assumes that there is an InkPresenter called presenter.

C#
private void HitTestWithEraser(Point[] points)
{
    RectangleStylusShape eraser = new RectangleStylusShape(3, 3, 0);

    StrokeCollection strokes = presenter.Strokes.HitTest(points, eraser);

    foreach (Stroke s in strokes)
    {
        s.DrawingAttributes.Color = Colors.Purple;
    }
}

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

HitTest(IEnumerable<Point>, Int32)

Returns a collection of strokes that have at least the specified percentage of length within the specified area.

C#
public System.Windows.Ink.StrokeCollection HitTest(System.Collections.Generic.IEnumerable<System.Windows.Point> lassoPoints, int percentageWithinLasso);

Parameters

lassoPoints
IEnumerable<Point>

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

percentageWithinLasso
Int32

The acceptable length of the Stroke, as a percentage, for lassoPoints to contain.

Returns

A StrokeCollection that has strokes with at least the specified percentage within the Point array.

Exceptions

lassoPoints is null.

-or-

percentageWithinLasso is null.

lassoPoints contains an empty array.

percentageWithinLasso is less than 0 or greater than 100.

Examples

The following example demonstrates how to remove all strokes that are at least 80 percent within the specified lasso from a StrokeCollection. This is useful when a custom control enables the user to select ink with a lasso. To create a control that enables a user to select ink with a lasso, see How to: Select Ink from a Custom Control.

C#
// Remove the strokes within the lasso from the InkPresenter
public void RemoveStrokes(Point[] lasso)
{
    StrokeCollection strokes = presenter.Strokes.HitTest(lasso, 80);

    presenter.Strokes.Remove(strokes);
}

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10

HitTest(Point)

Returns a collection of strokes that intersect the specified point.

C#
public System.Windows.Ink.StrokeCollection HitTest(System.Windows.Point point);

Parameters

point
Point

The point to hit test.

Returns

A collection of Stroke objects that intersect the specified point.

Examples

The following example demonstrates how to get the strokes that intersect the specified Point. This example assumes that there is an InkPresenter called presenter.

C#
// Change the color of all the strokes at the specified position.
public void SelectStrokes(Point position)
{
    StrokeCollection selected = presenter.Strokes.HitTest(position, 5);

    foreach (Stroke s in selected)
    {
        s.DrawingAttributes.Color = Colors.Purple;
    }
}

Applies to

.NET Framework 4.8.1 dan versi lain
Produk Versi
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9, 10