Bagikan melalui


InkCollectorSystemGestureEventHandler Delegate

InkCollectorSystemGestureEventHandler Delegate

Represents the method that handles the Gesture event of an InkCollector.

Definition

Visual Basic .NET Public Delegate Sub InkCollectorSystemGestureEventHandler( _
ByVal sender As Object, _
ByVal e As InkCollectorSystemGestureEventArgs _
)
C# public delegate void InkCollectorSystemGestureEventHandler(
object sender,
InkCollectorSystemGestureEventArgs e
);
Managed C++ public: __gc __delegate void InkCollectorSystemGestureEventHandler(
Object *sender,
InkCollectorSystemGestureEventArgs *e
);

Parameters

sender System.Object. [in] Specifies the source InkCollector of this event.
e Microsoft.Ink.InkCollectorSystemGestureEventArgs. [in] Specifies the InkCollectorSystemGestureEventArgs object that contains the event data.

Delegate Information

Namespace Microsoft.Ink
Assembly Microsoft.Ink (microsoft.ink.dll)
Strong Name Microsoft.Ink, Version=1.7.4009.0, Culture=neutral, PublicKeyToken=a2870d9cc4d021c8

Remarks

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

System gestures are useful because they give information about the Cursor object that is being used to create the gesture. They also provide shortcuts to combinations of mouse events and are "cheaper" ways to detect mouse events.

For example, instead of looking for a MouseUp/MouseDown pair of events with no other mouse events occurring in between, you can look for the Tap or RightTap system gestures.

As another example, instead of listening for MouseDown/MouseMove events and getting numerous MouseMove messages, you can watch for the Drag or RightDrag system gestures as long as you're not interested in the (x, y) coordinates of every position of the mouse. This allows you to receive only one message instead of numerous MouseMove messages.

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

Examples

[C#]

This simple 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)
        {
            Gesture theGesture = e.Gestures[0];
            statusBar1.Text = theGesture.Id.ToString();
            // Cancelling the gesture will cause the ink to remain.
            if (theGesture.Id == ApplicationGesture.ChevronDown)
                e.Cancel = true;
        }

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

        // Set all of the ApplicationGestures' status
        // to false on the InkCollector object.
        private void ClearAppGestures()
        {
            ApplicationGesture test = ApplicationGesture.NoGesture;
            Array theGestures = System.Enum.GetValues(test.GetType());
            foreach (ApplicationGesture theGesture in theGestures)
            {
                theInkCollector.SetGestureStatus(theGesture, 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, with
'the addition of a Status Bar, StatusBar1.
#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 theGesture As Gesture = e.Gestures(0)
        StatusBar1.Text = theGesture.Id.ToString()
        'Cancelling the gesture will cause the ink to remain.
        If theGesture.Id = ApplicationGesture.ChevronDown Then
            e.Cancel = True
        End If
     End Sub

    Private Sub SystemGesture_Event( _
        ByVal sender As Object, _
        ByVal e As InkCollectorSystemGestureEventArgs)
        StatusBar1.Text = "System: " + e.Id.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 theGestures As Array = System.Enum.GetValues(test.GetType())
        Dim theGesture As ApplicationGesture
        For Each theGesture In theGestures
            theInkCollector.SetGestureStatus(theGesture, 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