共用方式為


InkOverlay.SelectionMoved Event

InkOverlay.SelectionMoved Event

Occurs when the position of the current selection has changed, such as through alterations to the user interface, cut-and-paste procedures, or the Selection property.

Definition

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

Remarks

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

When you create an InkOverlaySelectionMovedEventHandler 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.

To get the old bounding rectangle of the collection of strokes that has been moved, use the OldSelectionBoundingRect of the InkOverlaySelectionMovedEventArgs object. To get the new bounding rectangle, call the Selection.GetBoundingBox method.

Examples

[C#]

This C# example demonstrates how to affect a selection after it has been moved. If it has been moved so that any of it is off the left or top side of the control, then it moves the selection back to its original position.

using Microsoft.Ink;
//...
  theInkOverlay.SelectionMoved += new InkOverlaySelectionMovedEventHandler(theInkOverlay_SelectionMoved);
//...
  private void theInkOverlay_SelectionMoved(object sender, InkOverlaySelectionMovedEventArgs e)
  {
       Rectangle newBounds = theInkOverlay.Selection.GetBoundingBox();
       // Check if we have gone off the left or top sides of the window.
       if (newBounds.Left < 0 || newBounds.Top < 0)
       {
           // Move to back to original spot
           theInkOverlay.Selection.Move(e.OldSelectionBoundingRect.Left - newBounds.Left,
               e.OldSelectionBoundingRect.Top - newBounds.Top);

           // Trick to insure that selection handles are updated
           theInkOverlay.Selection = theInkOverlay.Selection;
       }
   }
//...

[Visual Basic .NET]

This Microsoft® Visual Basic® .NET example demonstrates how to affect a selection after it has been moved. If it has been moved so that any of it is off the left or top side of the control, then it moves the selection back to its original position.

Imports Microsoft.Ink
'...
    Private WithEvents theInkOverlay As InkOverlay
'...
    Private Sub theInkOverlay_SelectionMoved(ByVal sender As Object, _
    ByVal e As Microsoft.Ink.InkOverlaySelectionMovedEventArgs) Handles theInkOverlay.SelectionMoved
        Dim newBounds As Rectangle = theInkOverlay.Selection.GetBoundingBox()
        'Check if we have gone off the left or top sides of the window.
        If newBounds.Left < 0 Or newBounds.Top < 0 Then
            'Move to back to original spot
            theInkOverlay.Selection.Move(e.OldSelectionBoundingRect.Left - newBounds.Left, _
                e.OldSelectionBoundingRect.Top - newBounds.Top)

            'Trick to insure that selection handles are updated
            theInkOverlay.Selection = theInkOverlay.Selection
        End If
    End Sub
'...

See Also