# StrokeCollection.HitTest 方法

## 多載

 傳回在指定矩形內具有指定百分比長度以上的筆劃集合。Returns a collection of strokes that have at least the specified percentage of length within the specified rectangle. 傳回與指定區域交集的筆劃集合。Returns a collection of strokes that intersect the specified area. 傳回與指定路徑交集的筆劃集合。Returns a collection of strokes that intersect with the specified path. 傳回在指定區域內具有指定百分比長度以上的筆劃集合。Returns a collection of strokes that have at least the specified percentage of length within the specified area. 傳回與指定點交集的筆劃集合。Returns a collection of strokes that intersect the specified 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

percentageWithinBounds
Int32

#### 傳回

StrokeCollection，其中具有在 Rect 中佔指定百分比以上的筆劃。A StrokeCollection that has strokes with at least the specified percentage within the Rect.

### 範例

``````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``

point
Point

diameter
Double

### 範例

``````// 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``

#### 參數

path
IEnumerable<Point>

Point 型別的陣列，表示要進行點擊測試的路徑。An array to type Point that represents the path to be hit tested.

stylusShape
StylusShape

StylusShape，可指定 `eraserPath` 的形狀。The StylusShape that specifies the shape of `eraserPath`.

#### 傳回

`path` 交集之筆劃的 StrokeCollectionA StrokeCollection of strokes that intersect with `path`.

### 範例

``````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 型別的陣列，表示要進行點擊測試的區域界限。An array of type Point that represents the bounds of the area to be hit tested.

percentageWithinLasso
Int32

`lassoPoints` 所包含 Stroke 的可接受長度 (以百分比表示)。The acceptable length of the Stroke, as a percentage, for `lassoPoints` to contain.

#### 傳回

StrokeCollection，其中具有在 Point 陣列中佔指定百分比以上的筆劃。A StrokeCollection that has strokes with at least the specified percentage within the Point array.

#### 例外狀況

`lassoPoints``null``lassoPoints` is `null`.

-或--or- `percentageWithinLasso``null``percentageWithinLasso` is `null`.

`lassoPoints` 包含空陣列。`lassoPoints` contains an empty array.

`percentageWithinLasso` 小於 0 或大於 100。`percentageWithinLasso` is less than 0 or greater than 100.

### 範例

``````// 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``

point
Point

### 範例

``````// 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
``````