共用方式為


Stroke.GetRectangleIntersections 方法

傳回 StrokeIntersection 結構的陣列,表示 Stroke 物件與指定的矩形 (英文) 交集的位置。

命名空間:  Microsoft.Ink
組件:  Microsoft.Ink (在 Microsoft.Ink.dll 中)

語法

'宣告
Public Function GetRectangleIntersections ( _
    intersectRectangle As Rectangle _
) As StrokeIntersection()
'用途
Dim instance As Stroke
Dim intersectRectangle As Rectangle
Dim returnValue As StrokeIntersection()

returnValue = instance.GetRectangleIntersections(intersectRectangle)
public StrokeIntersection[] GetRectangleIntersections(
    Rectangle intersectRectangle
)
public:
array<StrokeIntersection>^ GetRectangleIntersections(
    Rectangle intersectRectangle
)
public StrokeIntersection[] GetRectangleIntersections(
    Rectangle intersectRectangle
)
public function GetRectangleIntersections(
    intersectRectangle : Rectangle
) : StrokeIntersection[]

參數

傳回值

型別:array<Microsoft.Ink.StrokeIntersection[]
傳回 StrokeIntersection 結構的陣列,表示 Stroke 物件與 intersectRectangle 參數交集的位置。

備註

這個方法會傳回零組或多組索引,表示與矩形交集之筆劃的開始和結束區段。如果筆劃直接通過矩形,在兩處與週框交集,則這組索引為針對每個交集的浮點索引值所設。如果筆劃與矩形交集超過兩次,則索引數會隨交集次數增加。

如果筆劃是在測試矩形內開始,則第一個 StrokeIntersection 項目的 BeginIndex 屬性會設為 -1。如果筆劃是在測試矩形內結束,則最後一個 StrokeIntersection 項目的 EndIndex 屬性會設為 -1。如果筆劃完全包含在矩形內,則傳回的陣列會包含單一 StrokeIntersection 結構,其中 BeginIndex 屬性和 EndIndex 屬性都會設為 -1。如果筆劃完全位於測試矩形外,則會傳回空的 StrokeIntersection 陣列。

例如,如果筆劃是從測試矩形內開始、離開矩形週框、回到矩形內,並再次離開,則 GetRectangleIntersections 方法可能傳回 {{-1, 1.4}, {5.5, 10.1}},描述這兩個落在矩形內的筆劃區段。

這個方法傳回的 StrokeIntersection 結構包含成對的浮點索引值,會指出交集發生的位置。浮點索引是表示 Stroke 物件中兩點之間某個位置的浮點值。舉例來說,如果 0.0 是筆劃的第一點,而 1.0 是筆劃的第二點,0.5 即為第一點和第二點之間的中間處。同樣地,浮點索引值 37.25 則表示筆劃中沿著 37 和 38 兩點間線條上百分之 25 的位置。

範例

這個範例會刪除傳遞的 Stroke 物件中位於指定之矩形 (英文) 結構內的所有區段。這是透過檢查 StrokeIntersection 結構,找出傳遞之 Stroke 物件的分割位置以及要刪除的區段來完成的。

Private Sub DeleteInsideRectangle(ByVal S As Stroke, ByVal R As Rectangle)
    ' get the StrokeIntersection array
    Dim SI() As StrokeIntersection = S.GetRectangleIntersections(R)
    ' examine each StrokeIntersection
    ' must work backwards through the array so that when splitting, 
    ' the remaining intersections are still valid for S
    For k As Integer = SI.Length - 1 To 0 Step -1

        Dim enterRect As Single = SI(k).BeginIndex
        Dim exitRect As Single = SI(k).EndIndex

        ' check if the whole stroke is inside the rectangle
        ' if so, delete the stroke
        If enterRect = -1 And exitRect = -1 Then
            S.Ink.DeleteStroke(S)
            Continue For
        End If

        ' check if a segment enters and exits the rectangle
        ' if so, split and delete the segment inside the rectangle
        If enterRect > 0 And exitRect > 0 Then
            ' the stroke resulting from split() is outside, keep it
            S.Split(exitRect)
            ' the stroke from this split() is inside, delete it
            Dim temp As Stroke = S.Split(enterRect)
            temp.Ink.DeleteStroke(temp)
            Continue For
        End If

        ' check if stroke starts inside the rectangle and goes outside
        ' if so, split and delete the segment inside the rectangle
        If enterRect = -1 And exitRect > 0 Then
            ' the stroke resulting from split() is outside, keep it
            S.Split(exitRect)
            ' delete the remaining segment of the stroke
            S.Ink.DeleteStroke(S)
            Continue For
        End If

        ' check if stroke starts outside the rectangle and ends inside
        ' if so, split and delete the segment inside the rectangle
        If enterRect > 0 And exitRect = -1 Then
            Dim temp2 As Stroke = S.Split(enterRect)
            temp2.Ink.DeleteStroke(temp2)
        End If
    Next
End Sub
private void DeleteInsideRectangle(Stroke S, Rectangle R)
{
    // get the StrokeIntersection array
    StrokeIntersection[] SI = S.GetRectangleIntersections(R);

    // examine each StrokeIntersection
    // must work backwards through the array so that when splitting, 
    // the remaining intersections are still valid for S
    for (int k = SI.Length - 1; k >= 0; k--)
    {
        float enterRect = SI[k].BeginIndex;
        float exitRect = SI[k].EndIndex;

        // check if the whole stroke is inside the rectangle
        // if so, delete the stroke
        if (enterRect == -1 && exitRect == -1)
        {
            S.Ink.DeleteStroke(S);
            continue;
        }

        // check if a segment enters and exits the rectangle
        // if so, split and delete the segment inside the rectangle
        if (enterRect > 0 && exitRect > 0)
        {
            // the stroke resulting from split() is outside, keep it
            S.Split(exitRect);
            // the stroke from this split() is inside, delete it
            Stroke temp = S.Split(enterRect);
            temp.Ink.DeleteStroke(temp);
            continue;
        }

        // check if stroke starts inside the rectangle and goes outside
        // if so, split and delete the segment inside the rectangle
        if (enterRect == -1 && exitRect > 0)
        {
            // the stroke resulting from split() is outside, keep it
            S.Split(exitRect);
            // delete the remaining segment of the stroke
            S.Ink.DeleteStroke(S);
            continue;
        }

        // check if stroke starts outside the rectangle and ends inside
        // if so, split and delete the segment inside the rectangle
        if (enterRect > 0 && exitRect == -1)
        {
            Stroke temp2 = S.Split(enterRect);
            temp2.Ink.DeleteStroke(temp2);
        }
    }
}

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 並不支援各種平台的所有版本。如需支援平台版本的相關資訊,請參閱 .NET Framework 系統需求

版本資訊

.NET Framework

支援版本:3.0

請參閱

參考

Stroke 類別

Stroke 成員

Microsoft.Ink 命名空間

Stroke.FindIntersections

StrokeIntersection