StrokeCollection.HitTest 方法

定义

返回一个包含在指定区域内的笔画的集合。

重载

HitTest(Rect, Int32)

返回一个至少有指定百分比的长度包含在指定矩形内的笔画的集合。

HitTest(Point, Double)

返回一个与指定区域相交的笔画的集合。

HitTest(IEnumerable<Point>, StylusShape)

返回一个与指定路径相交的笔画的集合。

HitTest(IEnumerable<Point>, Int32)

返回一个至少有指定百分比的长度包含在指定区域内的笔画的集合。

HitTest(Point)

返回一个与指定点相交的笔画的集合。

HitTest(Rect, Int32)

返回一个至少有指定百分比的长度包含在指定矩形内的笔画的集合。

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

参数

bounds
Rect

Rect,用于指定要进行命中测试的边界。

percentageWithinBounds
Int32

必须存在于边界内的笔画的最小必需长度,达到此长度便视为命中。

返回

StrokeCollection,其包含的笔画至少有指定百分比的长度位于 Rect 内。

示例

以下示例清除 在 的边界内至少为 50% 的 Rect笔划。 此示例假定有一个名为 InkPresenterpresenter

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

presenter.Strokes.Remove(strokes);
Dim rect As Rect = New Rect(100, 100, 200, 200)
Dim strokes As StrokeCollection = presenter.Strokes.HitTest(rect, 50)

presenter.Strokes.Remove(strokes)

适用于

HitTest(Point, Double)

返回一个与指定区域相交的笔画的集合。

public:
 System::Windows::Ink::StrokeCollection ^ HitTest(System::Windows::Point point, double diameter);
public System.Windows.Ink.StrokeCollection HitTest (System.Windows.Point point, double diameter);
member this.HitTest : System.Windows.Point * double -> System.Windows.Ink.StrokeCollection
Public Function HitTest (point As Point, diameter As Double) As StrokeCollection

参数

point
Point

要进行命中测试的 Point

diameter
Double

要进行命中测试的 Point 的周围区域的大小。

返回

一个与指定点相交的 Stroke 对象的集合。

示例

以下示例演示如何获取与指定的 Point相交的笔划。 此示例假定有一个名为 InkPresenterpresenter

// 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;
    }
}
' Change the color of all the strokes at the specified position.
Public Sub SelectStrokes(ByVal position As Point)

    Dim selected As StrokeCollection = presenter.Strokes.HitTest(position, 5)

    Dim s As Stroke
    For Each s In selected
        s.DrawingAttributes.Color = Colors.Purple
    Next s

End Sub

适用于

HitTest(IEnumerable<Point>, StylusShape)

返回一个与指定路径相交的笔画的集合。

public:
 System::Windows::Ink::StrokeCollection ^ HitTest(System::Collections::Generic::IEnumerable<System::Windows::Point> ^ path, System::Windows::Ink::StylusShape ^ stylusShape);
public System.Windows.Ink.StrokeCollection 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 -> System.Windows.Ink.StrokeCollection
Public Function HitTest (path As IEnumerable(Of Point), stylusShape As StylusShape) As StrokeCollection

参数

path
IEnumerable<Point>

类型 Point 的数组,表示要进行命中测试的路径。

stylusShape
StylusShape

StylusShape,指定 eraserPath 的形状。

返回

path 相交的笔画的 StrokeCollection

示例

以下示例更改与 数组创建 Point 的路径相交的所有笔划的颜色。 此示例假定有一个名为 InkPresenterpresenter

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;
    }
}
Private Sub HitTestWithEraser(ByVal points() As Point)
    Dim eraser As RectangleStylusShape = New RectangleStylusShape(3, 3, 0)

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

    Dim s As Stroke
    For Each s In strokes
        s.DrawingAttributes.Color = Colors.Purple
    Next
End Sub

适用于

HitTest(IEnumerable<Point>, Int32)

返回一个至少有指定百分比的长度包含在指定区域内的笔画的集合。

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

参数

lassoPoints
IEnumerable<Point>

Point 类型的数组,用于表示要进行命中测试的区域的边界。

percentageWithinLasso
Int32

Stroke 包含在 lassoPoints 内的可接受长度,以百分比表示。

返回

StrokeCollection,其包含的笔画至少有指定百分比的长度位于 Point 数组内。

例外

lassoPointsnull

- 或 -

percentageWithinLassonull

lassoPoints 包含空数组。

percentageWithinLasso 小于 0 或大于 100。

示例

以下示例演示如何从 StrokeCollection中移除指定套索内至少 80% 的所有笔划。 当自定义控件允许用户选择带有套索的墨迹时,这非常有用。 若要创建允许用户使用套索选择墨迹的控件,请参阅 如何:从自定义控件中选择墨迹

// 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);
}
' Remove the strokes within the lasso from the InkPresenter
Public Sub RemoveStrokes(ByVal lasso As Point())

    If lasso Is Nothing Then
        Return
    End If

    Dim strokes As StrokeCollection = _
        presenter.Strokes.HitTest(lasso, 80)

    presenter.Strokes.Remove(strokes)

End Sub

适用于

HitTest(Point)

返回一个与指定点相交的笔画的集合。

public:
 System::Windows::Ink::StrokeCollection ^ HitTest(System::Windows::Point point);
public System.Windows.Ink.StrokeCollection HitTest (System.Windows.Point point);
member this.HitTest : System.Windows.Point -> System.Windows.Ink.StrokeCollection
Public Function HitTest (point As Point) As StrokeCollection

参数

point
Point

要进行命中测试的点。

返回

一个与指定点相交的 Stroke 对象的集合。

示例

以下示例演示如何获取与指定的 Point相交的笔划。 此示例假定有一个名为 InkPresenterpresenter

// 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;
    }
}
' Change the color of all the strokes at the specified position.
Public Sub SelectStrokes(ByVal position As Point)

    Dim selected As StrokeCollection = presenter.Strokes.HitTest(position, 5)

    Dim s As Stroke
    For Each s In selected
        s.DrawingAttributes.Color = Colors.Purple
    Next s

End Sub

适用于