Share via


Ink.DeleteStrokes Method (Strokes)

Deletes the specified Strokes collection from the Ink object.

Namespace:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Syntax

'Declaration
Public Sub DeleteStrokes ( _
    strokes As Strokes _
)
'Usage
Dim instance As Ink 
Dim strokes As Strokes

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

Parameters

Remarks

The Ink object renumbers the indices of the remaining Stroke objects in the Ink object if the Stroke objects that were deleted do not fall at the end of the Ink object's Strokes collection.

The DeleteStrokes method can result in an error if called while the user is actively laying down ink.

Note

A Strokes collection that points to an Ink.Strokes property become invalid when Stroke objects that are contained in the original collection are deleted from the Ink object. For example, if there is a named Strokes collection, theStrokesToo, that is based on an Ink object's Strokes property, theStrokes, and you call the DeleteStrokes method on theStrokes, then theStrokesToo becomes invalid.

To delete only one Stroke object at a time, call the DeleteStroke method.

Examples

This example contains a sample function that deletes all of the Stroke objects of the passed InkOverlay object that contain a Point to the left (in pixel space) of parameter 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();
}

Platforms

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

Ink Class

Ink Members

DeleteStrokes Overload

Microsoft.Ink Namespace

Strokes

Ink.DeleteStroke

Ink.CreateStroke

Ink.CreateStrokes