Stroke.HitTest 方法

定義

傳回值,指出 Stroke 是否與特定區域交集或在特定區域內部。

多載

HitTest(Point)

傳回值,指出目前 Stroke 是否與指定點交集。

HitTest(IEnumerable<Point>, Int32)

傳回值,指出目前 Stroke 是否在特定界限內。

HitTest(IEnumerable<Point>, StylusShape)

傳回指定路徑是否使用指定的 StrokeStylusShape 交集。

HitTest(Point, Double)

傳回值,指出目前 Stroke 是否與指定區域交集。

HitTest(Rect, Int32)

傳回值,指出 Stroke 是否位於指定矩形的界限內。

備註

您可以使用 HitTest 方法來判斷 Stroke 是否與特定點交集,或是在指定的界限內。

下列方法會檢查 是否 Stroke 交集 。

下列方法會檢查 是否 Stroke 括住 。

HitTest(Point)

傳回值,指出目前 Stroke 是否與指定點交集。

public:
 bool HitTest(System::Windows::Point point);
public bool HitTest (System.Windows.Point point);
member this.HitTest : System.Windows.Point -> bool
Public Function HitTest (point As Point) As Boolean

參數

point
Point

要進行點擊測試的 Point

傳回

Boolean

如果 point 與目前筆劃交集,則為 true,否則為 false

範例

如果它與特定區域交集,下列範例會變更 的 Stroke 色彩。

Point myPoint = new Point(100, 100);

if (myStroke.HitTest(myPoint, 10))
{
    myStroke.DrawingAttributes.Color = Colors.Red;
}
Dim myPoint As New System.Windows.Point(100, 100)

If myStroke.HitTest(myPoint, 10) Then
    myStroke.DrawingAttributes.Color = Colors.Red
End If

備註

這個方法的行為與多載 HitTest(Point, Double) 方法在 1 時 diameter 的行為相同。

適用於

HitTest(IEnumerable<Point>, Int32)

傳回值,指出目前 Stroke 是否在特定界限內。

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

參數

lassoPoints
IEnumerable<Point>

Point 型別的陣列,表示要進行點擊測試的區域界限。

percentageWithinLasso
Int32

Stroke 長度的百分比,必須在 lassoPoints 內這樣 Stroke 才會被視為已點擊。

傳回

Boolean

如果目前筆劃在指定界限內,則為 true,否則為 false

範例

如果至少 80% 的筆劃在 的界限 myPoints 內,下列範例會轉譯紫色的筆劃。

Point[] myPoints = new Point[] {
    new Point(100, 100),
    new Point(200, 100),
    new Point(200, 200),
    new Point(100, 200)};

if (aStroke.HitTest(myPoints, 80))
{
    aStroke.DrawingAttributes.Color = Colors.Purple;
}
Dim myPoints() As System.Windows.Point = _
                      {New System.Windows.Point(100, 100), _
                       New System.Windows.Point(200, 100), _
                       New System.Windows.Point(200, 200), _
                       New System.Windows.Point(100, 200)}

If aStroke.HitTest(myPoints, 80) Then
    aStroke.DrawingAttributes.Color = Colors.Purple
End If

備註

方法會 HitTest 連接 中的 lassoPoints 第一個和最後一個點,以建立套索。

適用於

HitTest(IEnumerable<Point>, StylusShape)

傳回指定路徑是否使用指定的 StrokeStylusShape 交集。

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

參數

path
IEnumerable<Point>

後續用於點擊測試的路徑 stylusShape

stylusShape
StylusShape

要用來點擊測試的 path 圖案。

傳回

Boolean

如果 stylusShape 與目前筆劃交集,則為 true,否則為 false

範例

如果筆劃與 的路徑 myPoints 交集,下列程式碼會呈現紫色的筆劃。

Point[] myPoints = new Point[] {
    new Point(100, 100),
    new	Point(200, 100),
    new	Point(200, 200),
    new	Point(100, 200)};

EllipseStylusShape myStylus = new EllipseStylusShape(5.0, 5.0, 0.0);

if (aStroke.HitTest(myPoints, myStylus))
{
    aStroke.DrawingAttributes.Color = Colors.Purple;
}
Dim myPoints() As System.Windows.Point = _
                      {New System.Windows.Point(100, 100), _
                       New System.Windows.Point(200, 100), _
                       New System.Windows.Point(200, 200), _
                       New System.Windows.Point(100, 200)}

Dim myStylus As New EllipseStylusShape(5.0, 5.0, 0.0)

If aStroke.HitTest(myPoints, myStylus) Then
    aStroke.DrawingAttributes.Color = Colors.Purple
End If

備註

方法 HitTest 會使用 stylusShape 來點擊測試沿著 eraserPath 的筆劃。

適用於

HitTest(Point, Double)

傳回值,指出目前 Stroke 是否與指定區域交集。

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

參數

point
Point

Point,定義要點擊測試的區域中央。

diameter
Double

要點擊測試的區域直徑。

傳回

Boolean

如果指定區域與目前筆劃交集,則為 true,否則為 false

範例

如果它與特定區域交集,下列範例會變更 的 Stroke 色彩。

Point myPoint = new Point(100, 100);

if (myStroke.HitTest(myPoint, 10))
{
    myStroke.DrawingAttributes.Color = Colors.Red;
}
Dim myPoint As New System.Windows.Point(100, 100)

If myStroke.HitTest(myPoint, 10) Then
    myStroke.DrawingAttributes.Color = Colors.Red
End If

適用於

HitTest(Rect, Int32)

傳回值,指出 Stroke 是否位於指定矩形的界限內。

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

參數

bounds
Rect

Rect,表示要點擊測試的區域界限。

percentageWithinBounds
Int32

Stroke 長度的百分比,必須在 percentageWithinBounds 內這樣 Stroke 才會被視為已點擊。

傳回

Boolean

如果目前筆劃位於 bounds 的界限內,則為 true;否則為 false

範例

如果筆劃中至少有 80% 的筆劃位於 內 Rect ,下列範例會呈現紫色筆劃。

Rect rect1 = new Rect(100, 100, 100, 100);

if (aStroke.HitTest(rect1, 80))
{
    aStroke.DrawingAttributes.Color = Colors.Purple;
}
Dim rect1 As New Rect(100, 100, 100, 100)

If aStroke.HitTest(rect1, 80) Then
    aStroke.DrawingAttributes.Color = Colors.Purple
End If

適用於