Condividi tramite


InkOverlay.StrokesDeleting Event

InkOverlay.StrokesDeleting Event

Occurs before strokes are deleted from the Ink property.

Definition

Visual Basic .NET Public Event StrokesDeleting As InkOverlayStrokesDeletingEventHandler
C# public event InkOverlayStrokesDeletingEventHandler StrokesDeleting;
Managed C++ public: __event InkOverlayStrokesDeletingEventHandler StrokesDeleting;

Remarks

The event handler receives an argument of type InkOverlayStrokesDeletingEventArgs that contains data about this event.

When you create an InkOverlayStrokesDeletingEventHandler delegate, you identify the method that will handle the event. To associate the event with your event handler, add an instance of the delegate to the event. The event handler is called whenever the event occurs, unless you remove the delegate. For performance reasons, the default event interest is off but is turned on automatically if you add an event handler.

Examples

[C#]

This C# example demonstrates a simple undo mechanism for the last delete that you made by using the StrokesDeleting event. When the MenuItem Leave Site named menuItemUndoDelete is clicked, then the strokes that were previously deleted are added back in.

using Microsoft.Ink;
  private Ink inkForDeletedStrokes;
//...
      theInkOverlay.StrokesDeleting +=
          new InkOverlayStrokesDeletingEventHandler(theInkOverlay_StrokesDeleting);
//...
  private void theInkOverlay_StrokesDeleting(object sender, InkOverlayStrokesDeletingEventArgs e)
  {
      // Store strokes for later undo.
      // You need to store them in a separate Ink object so that they don't get
      // completely deleted.
      inkForDeletedStrokes = new Ink();
      inkForDeletedStrokes.AddStrokesAtRectangle(e.StrokesToDelete,
          e.StrokesToDelete.GetBoundingBox());
  }

  private void menuItemUndoDelete_Click(object sender, System.EventArgs e)
  {
      if (inkForDeletedStrokes != null)
      {
          // Add strokes back.  (You need to use Ink.AddStrokesAtRectangle as opposed
          // to Strokes.Add because you are dealing with two different Ink objects.)
          theInkOverlay.Ink.AddStrokesAtRectangle(inkForDeletedStrokes.Strokes,
              inkForDeletedStrokes.Strokes.GetBoundingBox());

          inkForDeletedStrokes = null;

          // For best performance, you should Invalidate the rectangle created by the
          // bounding box (converted from ink space to pixel space).  For simplicity,
          // we will just refresh the entire control.
          Refresh();
      }
  }
//...

[Visual Basic .NET]

This Microsoft® Visual Basic® .NET example demonstrates a simple undo mechanism for the last delete that you made by using the StrokesDeleting event. When the MenuItem Leave Site named MenuItemUndoDelete is clicked, then the strokes that were previously deleted are added back in.

Imports Microsoft.Ink
'...
    Private inkForDeletedStrokes As Ink
    Private WithEvents theInkOverlay As InkOverlay
'...
    Private Sub theInkOverlay_StrokesDeleting(ByVal sender As Object, _
    ByVal e As Microsoft.Ink.InkOverlayStrokesDeletingEventArgs) _
    Handles theInkOverlay.StrokesDeleting
        'Store strokes for later undo.
        'You need to store them in a separate Ink object so that they don't get
        'completely deleted.
        inkForDeletedStrokes = New Ink()
        inkForDeletedStrokes.AddStrokesAtRectangle(e.StrokesToDelete, _
            e.StrokesToDelete.GetBoundingBox())
    End Sub

    Private Sub MenuItemUndoDelete_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) _
    Handles MenuItemUndoDelete.Click
        If Not inkForDeletedStrokes Is Nothing Then
            'Add strokes back.  (You need to use Ink.AddStrokesAtRectangle as opposed
            'to Strokes.Add because you are dealing with two different Ink objects.)
            theInkOverlay.Ink.AddStrokesAtRectangle(inkForDeletedStrokes.Strokes, _
                    inkForDeletedStrokes.Strokes.GetBoundingBox())

            inkForDeletedStrokes = Nothing

            'For best performance, you should Invalidate the rectangle created by the
            'bounding box (converted from ink space to pixel space).  For simplicity,
            'we will just refresh the entire control.
            Refresh()
       End If
    End Sub

See Also