共用方式為


Ink.DeleteStrokes 方法 (Strokes)

Ink 物件刪除指定的 Strokes 集合。

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

語法

'宣告
Public Sub DeleteStrokes ( _
    strokes As Strokes _
)
'用途
Dim instance As Ink
Dim strokes As Strokes

instance.DeleteStrokes(strokes)
public void DeleteStrokes(
    Strokes strokes
)
public:
void DeleteStrokes(
    Strokes^ strokes
)
public void DeleteStrokes(
    Strokes strokes
)
public function DeleteStrokes(
    strokes : Strokes
)

參數

備註

如果刪除的 Stroke 物件不在 Ink 物件之 Strokes 集合的結尾處,則 Ink 物件會將 Ink 物件中剩餘之 Stroke 物件的索引重新編號。

如果在使用者正停留在筆墨上時呼叫 DeleteStrokes 方法,可能會造成錯誤。

ms569577.alert_note(zh-tw,VS.90).gif注意事項:

當從 Ink 物件刪除原始集合所包含的 Stroke 物件時,指向 Ink.Strokes 屬性的 Strokes 集合就會無效。例如,如果具名 Strokes 集合 (theStrokesToo) 是依據 Ink 物件的 Strokes 屬性 (theStrokes) 為基礎,當您對 theStrokes 呼叫 DeleteStrokes 方法時,則 theStrokesToo 就會無效。

若一次只要刪除一個 Stroke 物件,請呼叫 DeleteStroke 方法。

範例

這個範例包含的範例函式,會將所傳遞 InkOverlay 物件的所有 Stroke 物件刪除,其中前者包含 Point 到參數 LeftInPixels 左邊 (於像素空間中)。

Private Sub DeleteStrokesByLeft(ByVal mInkOverlay As InkOverlay, ByVal LeftInPixels As Integer)
    ' Create a Point object based upon the Left parameter
    Dim ptLeft As Point = New Point(LeftInPixels, 0)

    ' Convert the point from pixel space to ink space dimensions
    ' InkOverlay.AttachedControl must be set
    Using g As Graphics = mInkOverlay.AttachedControl.CreateGraphics()
        mInkOverlay.Renderer.PixelToInkSpace(g, ptLeft)
    End Using

    ' Create a Strokes object to hold strokes to be deleted
    Dim strokesToDelete As Strokes = mInkOverlay.Ink.CreateStrokes()

    ' Access to the Strokes property returns a copy of the Strokes object.
    ' This copy must be implicitly (via using statement) or explicitly
    ' disposed of in order to avoid a memory leak.
    Using currentStrokes As Strokes = mInkOverlay.Ink.Strokes
        For Each S As Stroke In currentStrokes
            For Each strokePoint As Point In S.GetPoints()
                If (strokePoint.X < ptLeft.X) Then
                    ' Note: A particluar Stroke object might have several
                    ' points to the left of ptLeft.X - Therefore, the
                    ' following statement will be executed multiple times.
                    ' Even so, the Add method will not add the same stroke twice. 
                    strokesToDelete.Add(S)
                End If
            Next
        Next
    End Using
    If strokesToDelete.Count > 0 Then
        mInkOverlay.Ink.DeleteStrokes(strokesToDelete)
        mInkOverlay.AttachedControl.Invalidate()
    End If
    strokesToDelete.Dispose()
End Sub
private void DeleteStrokesByLeft(InkOverlay mInkOverlay, int LeftInPixels)
{
    // Create a Point object based upon the Left parameter
    Point ptLeft = new Point(LeftInPixels, 0);

    // Convert the point from pixel space to ink space dimensions
    // InkOverlay.AttachedControl must be set
    using (Graphics g = mInkOverlay.AttachedControl.CreateGraphics())
    {
        mInkOverlay.Renderer.PixelToInkSpace(g, ref ptLeft);
    }

    // Create a Strokes object to hold strokes to be deleted
    Strokes strokesToDelete = mInkOverlay.Ink.CreateStrokes();

    // Access to the Strokes property returns a copy of the Strokes object.
    // This copy must be implicitly (via using statement) or explicitly
    // disposed of in order to avoid a memory leak.
    using (Strokes currentStrokes = mInkOverlay.Ink.Strokes)
    {
        foreach (Stroke S in currentStrokes)
        {
            foreach (Point strokePoint in S.GetPoints())
            {
                if (strokePoint.X < ptLeft.X)
                {
                    // Note: A particluar Stroke object might have several
                    // points to the left of ptLeft.X - Therefore, the
                    // following statement will be executed multiple times.
                    // Even so, the Add method will not add the same stroke twice. 
                    strokesToDelete.Add(S);
                }
            }
        }
    }

    if (strokesToDelete.Count > 0)
    {
        mInkOverlay.Ink.DeleteStrokes(strokesToDelete);
        mInkOverlay.AttachedControl.Invalidate();
    }
    strokesToDelete.Dispose();
}

平台

Windows Vista

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

版本資訊

.NET Framework

支援版本:3.0

請參閱

參考

Ink 類別

Ink 成員

DeleteStrokes 多載

Microsoft.Ink 命名空間

Strokes

Ink.DeleteStroke

Ink.CreateStroke

Ink.CreateStrokes