共用方式為


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

StrokeCollection,其中具有在 Rect 中佔指定百分比以上的筆劃。

範例

下列範例會清除界限內 Rect 至少 50% 的筆劃。 此範例假設有 InkPresenter 名為 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)

傳回與指定區域交集的筆劃集合。

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 周圍區域大小。

傳回

StrokeCollection

與指定點交集的 Stroke 物件集合。

範例

下列範例示範如何取得與指定 Point 相交的筆劃。 此範例假設有 InkPresenter 名為 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)

傳回與指定路徑交集的筆劃集合。

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

範例

下列範例會變更與陣列所 Point 建立路徑相交之所有筆劃的色彩。 此範例假設有 InkPresenter 名為 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)

傳回在指定區域內具有指定百分比長度以上的筆劃集合。

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 陣列中佔指定百分比以上的筆劃。

例外狀況

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

要進行點擊測試的點。

傳回

StrokeCollection

與指定點交集的 Stroke 物件集合。

範例

下列範例示範如何取得與指定 Point 相交的筆劃。 此範例假設有 InkPresenter 名為 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

適用於