Share via


InkEdit.Gesture Event

Occurs when an application gesture is recognized.

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

Syntax

'Declaration
Public Event Gesture As InkEditGestureEventHandler
'Usage
Dim instance As InkEdit 
Dim handler As InkEditGestureEventHandler 

AddHandler instance.Gesture, handler
public event InkEditGestureEventHandler Gesture
public:
 event InkEditGestureEventHandler^ Gesture {
    void add (InkEditGestureEventHandler^ value);
    void remove (InkEditGestureEventHandler^ value);
}
JScript does not support events.

Remarks

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

When you create an InkEditGestureEventHandler delegate, you identify the method that handles 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 this event to occur, the InkEdit control must have interest in a set of application gestures. To set the InkEdit control's interest in a set of gestures, call the InkEdit.SetGestureStatus method. The InkEdit control does not recognize multiple stroke gestures.

For a list of specific application gestures, see the ApplicationGesture enumeration type. For more information about application gestures, see Using Gestures and Command Input on the Tablet PC.

The InkEdit control has default interest in and actions for the following gestures.

Gesture

Action

Down-left, Down-left-long

Enter

Right

Space

Left

Backspace

Up-right, Up-right-long

Tab

In the InkEdit control, a Gesture event is raised only if the gesture is the first stroke since either the last call to the Recognize method or the last firing of the recognition timeout.

If the Gesture event is cancelled, the Stroke event is raised for the Stroke objects that raised the Gesture event.

To alter the default action for a gesture

  • Add event handlers for the Gesture and Stroke events.

  • In the Gesture event handler, cancel the Gesture event for the gesture, and perform the alternate action for the gesture.

  • In the Stroke event handler, cancel the Stroke event for the Stroke object that raised the cancelled Gesture event.

Examples

This example demonstrates how you can subscribe to the Gesture event and the Stroke event to augment the functionality of an ApplicationGesture.

When the Gesture event fires, it examines the gesture and the current state of the InkEdit control. If necessary, the behavior of the gesture is modified and the event is cancelled.

Private Sub mInkEdit_Gesture(ByVal sender As Object, ByVal e As InkEditGestureEventArgs)
    ' There might be more than one gesture passed in InkEditGestureEventArgs 
    ' The gestures are arranged in order of confidence from most to least 
    ' This event handler is only concerned with the first (most confident) gesture 
    ' and only if the gesture is ApplicationGesture.Left with strong confidence 
    Dim G As Gesture = e.Gestures(0)
    If (ApplicationGesture.Left = G.Id And RecognitionConfidence.Strong = G.Confidence) Then 
        Dim pInkEdit As InkEdit = DirectCast(sender, InkEdit)
        ' by default, ApplicationGesture.Left maps to Backspace 
        ' If the insertion point is at the beginning of the text 
        ' and there is no text selected, then Backspace does not do anything. 
        ' In this case, we will alter the gesture to map to Delete instead 
        If (0 = pInkEdit.SelectionStart And 0 = pInkEdit.SelectionLength And pInkEdit.Text.Length > 0) Then 
            ' take out the first character of the string
            pInkEdit.Text = pInkEdit.Text.Remove(0, 1)
            ' save the stroke ID in a class level var for use in the Stroke event 
            Me.mStrokeID = e.Strokes(0).Id
            ' cancel the gesture so it won't perform the default action
            e.Cancel = True 
        End If 
    End If 
End Sub
private void mInkEdit_Gesture(object sender, InkEditGestureEventArgs e)
{
    // There might be more than one gesture passed in InkEditGestureEventArgs 
    // The gestures are arranged in order of confidence from most to least 
    // This event handler is only concerned with the first (most confident) gesture 
    // and only if the gesture is ApplicationGesture.Left with strong confidence
    Gesture G = e.Gestures[0];
    if (ApplicationGesture.Left == G.Id &&  RecognitionConfidence.Strong == G.Confidence)
    {
        InkEdit pInkEdit = (InkEdit)sender;

        // by default, ApplicationGesture.Left maps to Backspace 
        // If the insertion point is at the beginning of the text 
        // and there is no text selected, then Backspace does not do anything. 
        // In this case, we will alter the gesture to map to Delete instead 
        if (0 == pInkEdit.SelectionStart && 0 == pInkEdit.SelectionLength && pInkEdit.Text.Length > 0)
        {
            // take out the first character of the string
            pInkEdit.Text = pInkEdit.Text.Remove(0, 1);
            // save the stroke ID in a class level var for use in the Stroke event 
            this.mStrokeID = e.Strokes[0].Id;
            // cancel the gesture so it won't perform the default action
            e.Cancel = true;
        }
    }
}

When the Stroke event fires, the event is cancelled if the stroke is the one that was used to generate the gesture whose behavior was modified in the Gesture event. This prevents the stroke from rendering.

Private Sub mInkEdit_Stroke(ByVal sender As Object, ByVal e As InkEditStrokeEventArgs)
    e.Cancel = (e.Stroke.Id = Me.mStrokeID)
End Sub
private void mInkEdit_Stroke(object sender, InkEditStrokeEventArgs e)
{
    e.Cancel = (e.Stroke.Id == this.mStrokeID);
}

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

InkEdit Class

InkEdit Members

Microsoft.Ink Namespace

InkEditGestureEventArgs

ApplicationGesture

InkEdit.SetGestureStatus

InkEdit.RecoTimeout