# StrokeCollection.HitTest 方法

## 多載

 HitTest(Rect, Int32) 傳回在指定矩形內具有指定百分比長度以上的筆劃集合。 HitTest(Point, Double) 傳回與指定區域交集的筆劃集合。 HitTest(IEnumerable, StylusShape) 傳回與指定路徑交集的筆劃集合。 HitTest(IEnumerable, 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

percentageWithinBounds
Int32

#### 傳回

StrokeCollection

StrokeCollection，其中具有在 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``
``Public Function HitTest (point As Point, diameter As Double) As StrokeCollection``

point
Point

diameter
Double

StrokeCollection

### 範例

``````// 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` 的形狀。

#### 傳回

StrokeCollection

`path` 交集之筆劃的 StrokeCollection

### 範例

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

`lassoPoints` 所包含 Stroke 的可接受長度 (以百分比表示)。

#### 傳回

StrokeCollection

StrokeCollection，其中具有在 Point 陣列中佔指定百分比以上的筆劃。

#### 例外狀況

`lassoPoints``null`

-或- `percentageWithinLasso``null`

`lassoPoints` 包含空陣列。

`percentageWithinLasso` 小於 0 或大於 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``
``Public Function HitTest (point As Point) As StrokeCollection``

point
Point

StrokeCollection

### 範例

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