Bagikan melalui


InkCollector.Gesture Event

InkCollector.Gesture Event

Occurs when an application-specific gesture is recognized.

Definition

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

Remarks

Application gestures are defined as gestures that are supported within your application.

For this event to occur, the InkCollector must have interest in a set of application gestures. To set the InkCollector's interest in a set of gestures, call the SetGestureStatus method.

For a list of specific application gestures, see the ApplicationGesture enumeration type. For more information about application gestures, see Making Windows Work with a Pen.

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

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

When the CollectionMode property is set to GestureOnly, the timeout between when a user adds a gesture and when the Gesture event occurs is a fixed value that you cannot alter programmatically. Gesture recognition is faster in InkAndGesture mode.

To prevent the collection of ink while in InkAndGesture mode:

To prevent the flow of ink while gesturing, set DynamicRendering to False.

In addition to when inserting ink, the Gesture event is fired when in select or erase mode. You are responsible for tracking the editing mode and should be aware of the mode before interpreting the event.

Note: To recognize gestures, you must use an object or control that can collect ink.

Note: The InkCollector object uses the InkCollectorGestureEventHandler delegate to add a gesture event handler.

Examples

[C#]

This C# example displays gesture event information in the status bar of the main form window. Starting with a generic generated application, add a status bar called statusBar1 to the main form and add the following code.

//...
using Microsoft.Ink;

namespace CSGestureEvents
{
    public class Form1 : System.Windows.Forms.Form
    {
        private System.Windows.Forms.StatusBar statusBar1;
        // ... The generated code will be here.
        //Add this code following the implementation of Main():
        InkCollector theInkCollector;

        private void Form1_Load(object sender, System.EventArgs e)
        {
            // Initialize the InkCollector object.
            theInkCollector = new InkCollector(Handle);
            theInkCollector.CollectionMode = CollectionMode.InkAndGesture;
            ClearAppGestures(theInkCollector);
            // Turn on interest in the ChevronDown application gesture.
            theInkCollector.SetGestureStatus(ApplicationGesture.ChevronDown, true);
            theInkCollector.SetGestureStatus(ApplicationGesture.ChevronUp, true);
            theInkCollector.Gesture += new InkCollectorGestureEventHandler(Gesture_Event);
            theInkCollector.SystemGesture += new InkCollectorSystemGestureEventHandler(SystemGesture_Event);
            theInkCollector.Enabled = true;
        }

        private void Gesture_Event(object sender,
            InkCollectorGestureEventArgs e)
        {
            ApplicationGesture theGestureId = e.Gestures[0].Id;
            statusBar1.Text = theGestureId.ToString();
            // Cancelling the gesture will cause the ink to remain.
            if (theGestureId == ApplicationGesture.ChevronDown)
                e.Cancel = true;
        }

        private void SystemGesture_Event(object sender,
            InkCollectorSystemGestureEventArgs e)
        {
            SystemGesture theGestureId = e.Id;
            statusBar1.Text = "System: " + theGestureId.ToString() +
                " " + e.Point.ToString();
        }

        // Set all of the ApplicationGestures' status
        // to false on the InkCollector object.
        private void ClearAppGestures()
        {
            ApplicationGesture test = ApplicationGesture.NoGesture;
            System.Array theGestureIds = System.Enum.GetValues(test.GetType());
            foreach (ApplicationGesture theGestureId in theGestureIds)
            {
                theInkCollector.SetGestureStatus(theGestureId, false);
            }
        }

        // Event handler for the form's closed event
        private void Form1_Closed(object sender, System.EventArgs e)
        {
            theInkCollector.Dispose();
            theInkCollector = null;
        }
    }
}

[Visual Basic .NET]

This Microsoft® Visual Basic® .NET example displays gesture event information in the status bar of the main form window. Starting with a generic generated application, add a status bar called statusBar1 to the main form and add the following code.

Imports Microsoft.Ink
Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "
    'This contains the standard generated form code
    Private statusBar1 As System.Windows.Forms.StatusBar
#End Region

    Dim theInkCollector As InkCollector

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Initialize InkCollector.
        theInkCollector = New InkCollector(Handle)
        'Set the InkCollector to collect both ink and gestures.
        theInkCollector.CollectionMode = CollectionMode.InkAndGesture
        'Clear interest in all of the application gestures
        ClearAppGestures(theInkCollector)
        'Set the interest in only two gestures.
        theInkCollector.SetGestureStatus(ApplicationGesture.ChevronDown, True)
        theInkCollector.SetGestureStatus(ApplicationGesture.ChevronUp, True)
        'Add the handlers for application and system gestures.
        AddHandler theInkCollector.Gesture, AddressOf Gesture_Event
        AddHandler theInkCollector.SystemGesture, AddressOf SystemGesture_Event
        theInkCollector.Enabled = True
    End Sub

    Private Sub Gesture_Event(ByVal sender As Object, _
        ByVal e As InkCollectorGestureEventArgs)
        Dim theGestureId As ApplicationGesture = e.Gestures(0).Id
        StatusBar1.Text = theGestureId.ToString()
        'Cancelling the gesture will cause the ink to remain.
        If theGestureId = ApplicationGesture.ChevronDown Then
            e.Cancel = True
        End If
    End Sub

    Private Sub SystemGesture_Event( _
        ByVal sender As Object, _
        ByVal e As InkCollectorSystemGestureEventArgs)
        Dim theGestureId As SystemGesture = e.Id
        StatusBar1.Text = "System: " + theGestureId.ToString() + "   " + e.Point.ToString()
    End Sub

    ' Set all of the ApplicationGestures' status
    ' to false on the InkCollector object.
    Private Sub ClearAppGestures()
        Dim test As ApplicationGesture = ApplicationGesture.NoGesture
        Dim theGestureIds As System.Array = System.Enum.GetValues(test.GetType())
        Dim theGestureId As ApplicationGesture
        For Each theGestureId In theGestureIds
            theInkCollector.SetGestureStatus(theGestureId, False)
        Next
    End Sub

    'Event handler for the form's closed event
    Private Sub Form1_Closed(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Closed
        theInkCollector.Dispose()
        Set theInkCollector = Nothing
    End Sub
End Class

See Also