Freigeben über


Ink.DeleteStrokes Method

Ink.DeleteStrokes Method

Deletes the specified Strokes collection from the Ink object.

Definition

Visual Basic .NET Public Sub DeleteStrokes( _
ByVal strokes As Strokes _
)
C# public void DeleteStrokes(
Strokes strokes
);
Managed C++ public: void DeleteStrokes(
Strokes *strokes
);

Parameters

strokes Microsoft.Ink.Strokes. The Strokes collection to delete.

Exceptions

ArgumentException Leave Site: An invalid Stroke object was passed to the method. Verify that the Stroke object corresponds to this Ink object.
COMException Leave Site:
ObjectDisposedException Leave Site: The Ink object is disposed.

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

[C#]

This C# example contains a sample function that deletes all of the Stroke objects in the Ink object, theInk, that are to the left of the Point Leave Site parameter, thePoint, in pixel space. It then returns a count of the deleted Stroke objects.

public int DeleteStrokesOnLeft(
   System.Drawing.Point thePoint,
   Microsoft.Ink.Ink theInk,
   Microsoft.Ink.InkCollector theInkCollector,
   System.Drawing.Graphics g)
{
   // Convert the point from pixel space to ink space dimensions
   System.Drawing.Point ptLeft = thePoint;
   theInkCollector.Renderer.PixelToInkSpace(g, ref ptLeft);

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

   foreach (Stroke stroke in theInk.Strokes)
   {
      System.Drawing.Point[] ptStrokePoints = stroke.GetPoints();
      for (int i = 0; i < ptStrokePoints.Length; i++)
      {
         Point ptTest = ptStrokePoints[i];

         // If there is a point in this Stroke to the left of the parameter,
         if (ptTest.X < ptLeft.X)
         {
            // add this Stroke to the collection to delete
            strokesToDelete.Add(stroke);
         }
      }
   }
   if (0 < strokesToDelete.Count)
      theInk.DeleteStrokes(strokesToDelete);

   return strokesToDelete.Count;
}

[Visual Basic .NET]

This Microsoft® Visual Basic® .NET example contains a sample function that deletes all of the Stroke objects in the Ink object, theInk, that are to the left of the Point Leave Site parameter, thePoint, in pixel space. It then returns a count of the deleted Stroke objects.

Public Function DeleteStrokesOnLeft( _
   ByVal thePoint As System.Drawing.Point, _
   ByRef theInk As Microsoft.Ink.Ink, _
   ByRef theInkCollector As Microsoft.Ink.InkCollector, _
   ByRef g As System.Drawing.Graphics _
)
   Dim i As Integer
   Dim ptTest As Point
   Dim ptLeft As Point
   Dim stroke As Stroke
   Dim strokesToDelete As Strokes
   Dim ptStrokePoints() As System.Drawing.Point

   ' Convert the left parameter from pixels to ink space
   ptLeft = thePoint
   theInkCollector.Renderer.PixelToInkSpace(g, ptLeft)

   ' Create a Strokes object to hold strokes to be deleted
   strokesToDelete = theInk.CreateStrokes()

   For Each stroke In theInk.Strokes
      ptStrokePoints = stroke.GetPoints()
      For i = 0 To ptStrokePoints.Length - 1
         ptTest = ptStrokePoints(i)

         ' If there is a point in this Stroke to the left of the parameter,
         If ptTest.X < ptLeft.X Then
            ' add this Stroke to the collection to delete
            strokesToDelete.Add(stroke)
         End If
      Next
   Next
   If 0 < strokesToDelete.Count Then
      theInk.DeleteStrokes(strokesToDelete)
   End If
   Return strokesToDelete.Count
End Function

See Also