StrokeCollection.HitTest 方法

定義

傳回指定區域所包含的筆劃集合。Returns a collection of strokes contained within the specified area.

多載

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.

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

指定要進行點擊測試之界限的 RectA 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.

傳回

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

範例

下列範例會在的界限Rect內清除至少為 50% 的筆劃。The following example erases the strokes that are at least 50% within the bounds of the Rect. 這個範例假設有一個InkPresenter呼叫presenter的。This example assumes that there is an InkPresenter called presenter.

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)

傳回與指定區域交集的筆劃集合。Returns a collection of strokes that intersect the specified area.

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

要進行點擊測試的 PointThe Point to hit test.

diameter
Double

要點擊測試的 Point 周圍區域大小。The size of the area around the Point to hit test.

傳回

與指定點交集的 Stroke 物件集合。A collection of Stroke objects that intersect the specified point.

範例

下列範例示範如何取得與指定Point的相交的筆劃。The following example demonstrates how to get the strokes that intersect the specified Point. 這個範例假設有一個InkPresenter呼叫presenter的。This example assumes that there is an InkPresenter called presenter.

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

傳回與指定路徑交集的筆劃集合。Returns a collection of strokes that intersect with the specified path.

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.

範例

下列範例會變更與Point陣列所建立之路徑相交的所有筆劃的色彩。The following example changes the color of all the strokes that intersect the path that is created by the Point array. 這個範例假設有一個InkPresenter呼叫presenter的。This example assumes that there is an InkPresenter called presenter.

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)

傳回在指定區域內具有指定百分比長度以上的筆劃集合。Returns a collection of strokes that have at least the specified percentage of length within the specified area.

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.

例外狀況

lassoPointsnulllassoPoints is null.

-或--or- percentageWithinLassonullpercentageWithinLasso is null.

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

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

範例

下列範例示範如何從StrokeCollection在指定的套索中,移除至少 80% 的所有筆劃。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.

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

傳回與指定點交集的筆劃集合。Returns a collection of strokes that intersect the specified 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

要進行點擊測試的點。The point to hit test.

傳回

與指定點交集的 Stroke 物件集合。A collection of Stroke objects that intersect the specified point.

範例

下列範例示範如何取得與指定Point的相交的筆劃。The following example demonstrates how to get the strokes that intersect the specified Point. 這個範例假設有一個InkPresenter呼叫presenter的。This example assumes that there is an InkPresenter called presenter.

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

適用於