Stroke.HitTest 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
無論該 Stroke 地是否相交或位於某區域內,都會回傳。
多載
| 名稱 | Description |
|---|---|
| HitTest(Point) |
回傳一個表示電流 Stroke 是否與指定點相交的值。 |
| HitTest(IEnumerable<Point>, Int32) |
回傳一個表示電流 Stroke 是否在指定範圍內的值。 |
| HitTest(IEnumerable<Point>, StylusShape) |
回傳指定路徑是否與 相 Stroke 交,使用指定的 StylusShape。 |
| 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
參數
傳回
true若與point當前行程相交;否則,。 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)載diameter方法在 為 1 時相同。
適用於
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 列。
傳回
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)
回傳指定路徑是否與 相 Stroke 交,使用指定的 StylusShape。
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 測試。
傳回
true若與stylusShape當前行程相交;否則,。 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
參數
- diameter
- Double
要測試的區域直徑。
傳回
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
參數
傳回
true 若當前筆劃在 範圍內 bounds;否則, 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