InkOverlay.CollectionMode Property
InkOverlay.CollectionMode Property |
Gets or sets the collection mode that determines whether ink, gestures, or both are recognized as the user writes.
Definition
Visual Basic .NET Public Property CollectionMode As CollectionMode C# public CollectionMode CollectionMode { get; set; } Managed C++ public: __property CollectionMode* get_CollectionMode();
public: __property void set_CollectionMode(CollectionMode*);
Property Value
Microsoft.Ink.CollectionMode. The collection mode that determines whether ink, gestures, or both are recognized as the user writes.
This property is read/write. This property has no default value.
InkOnly0
Collects only ink, creating a stroke.
The InkCollector.Gesture, InkOverlay.Gesture, or InkPicture.Gesture event interest is set to false, meaning that gestures are not collected (all other event interests remain as they were).
GestureOnly1
Collects only gestures and does not create a stroke. Gestures can be either single- or multi-stroke. Multi-stroke gestures are accepted if the strokes are made within the time set by the built-in timer of the recognizer.
All stroke-related and packet-related events do not fire from the InkCollector object, InkOverlay object, or InkPicture control. Cursor events fire, and ink is always deleted.
The InkCollector.Gesture, InkOverlay.Gesture, or InkPicture.Gesture event interest is set to true, meaning that gestures are collected (all other event interests remain as they were).
InkAndGesture2
Accepts only single-stroke gestures. The InkCollector.Gesture, InkOverlay.Gesture, or InkPicture.Gesture event fires first, allowing you to cancel or accept the event. The default is to accept the event, except when NoGesture is the primary gesture. If the gesture is accepted, the ink is deleted. If the gesture is canceled, the stroke is not deleted and a InkCollector.Stroke, InkOverlay.Stroke, or InkPicture.Stroke event fires.
The InkCollector.Gesture, InkOverlay.Gesture, or InkPicture.Gesture event interest is set to true, meaning that gestures are collected (all other event interests remain as they were).
Exceptions
Remarks
Note: The InkOverlay object generates an error if you try to change the CollectionMode property while ink is being collected. To avoid this conflict, check the CollectingInk property before changing the CollectionMode property.
For a list of the modes that you can use, see the CollectionMode enumeration. However, when using the CollectionMode property on a system that has the Tablet PC SDK installed but that doesn't have recognizers installed, the mode cannot be set to GestureOnly or InkAndGesture.
The following behaviors occur for each of the CollectionMode values.
InkOnly mode
- Only ink is collected; gestures are not.
- The Gesture event interest is set to false (all other event interests remain as they were).
GestureOnly mode
- Only gestures are collected; ink is not. The strokes are deleted after they are sent to the gesture recognizer.
- The Gesture event interest is set to true (all other event interests remain as they were).
- The InkOverlay object does not fire the following stroke and packet related events: the CursorDown, Stroke, NewPackets, and NewInAirPackets events.
- Cursor events fire.
InkAndGesture mode
- Both ink and gestures are collected.
- Only single-stroke gestures are recognized.
- The Gesture event interest is set to true (all other event interests remain as they were).
- The Gesture event fires first, allowing you to accept or cancel the gesture when the InkOverlay object's OnGesture event handler is invoked. To cancel the geture, set the inherited Cancel property of the InkCollectorGestureEventArgs object to true. Canceling the gesture forces the InkOverlay object to collect the ink.
Changing the collection mode does not alter the status of individual gestures.
Unwanted behavior may occur when the CollectionMode property is set to InkAndGesture and an InkOverlay object's interest in a known gesture is set (by calling the SetGestureStatus method). If you draw ink that looks something like the known gesture and the known gesture is in the recognizer's list of alternates, the Gesture event fires and the ink disappears, even if the gesture is not the top alternate. To prevent the ink from disappearing when you want to collect the ink instead of the gesture, cancel collection of the gesture and set the inherited Cancel property of the InkCollectorGestureEventArgs object to true.
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 cannot be altered programmatically. Gesture recognition is faster in the InkAndGesture mode. To collect gestures only and prevent the collection of ink while in the InkAndGesture mode, you can:
- Set the CollectionMode property to InkAndGesture.
- In the Stroke event, delete the stroke.
- In the Gesture event, process the gesture.
- Set DynamicRendering to false to prevent the flow of ink while gesturing.
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 StatusBar control, statusBar1, to the main form and 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(): InkOverlay theInkOverlay; private void Form1_Load(object sender, System.EventArgs e) { // Initialize the InkOverlay object. theInkOverlay = new InkOverlay(Handle); theInkOverlay.CollectionMode = CollectionMode.InkAndGesture; ClearAppGestures(theInkOverlay); // Turn on interest in the ChevronDown application gesture. theInkOverlay.SetGestureStatus(ApplicationGesture.ChevronDown, true); theInkOverlay.SetGestureStatus(ApplicationGesture.ChevronUp, true); theInkOverlay.Gesture += new InkCollectorGestureEventHandler(Gesture_Event); theInkOverlay.SystemGesture += new InkCollectorSystemGestureEventHandler(SystemGesture_Event); theInkOverlay.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 InkOverlay object. private void ClearAppGestures(InkOverlay theInkOverlay) { ApplicationGesture test = ApplicationGesture.NoGesture; Array theGestures = System.Enum.GetValues(test.GetType()); foreach (ApplicationGesture theGesture in theGestures) { theInkOverlay.SetGestureStatus(theGesture, false); } } } }
[VB.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 StatusBar control, statusBar1, to the main form and 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 theInkOverlay As InkOverlay Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'Initialize InkOverlay. theInkOverlay = New InkOverlay(Handle) 'Set the InkOverlay to collect both ink and gestures. theInkOverlay.CollectionMode = CollectionMode.InkAndGesture 'Clear interest in all of the application gestures ClearAppGestures(theInkOverlay) 'Set our interest in only two gestures. theInkOverlay.SetGestureStatus(ApplicationGesture.ChevronDown, True) theInkOverlay.SetGestureStatus(ApplicationGesture.ChevronUp, True) 'Add the handlers for application and system gestures. AddHandler theInkOverlay.Gesture, AddressOf Gesture_Event AddHandler theInkOverlay.SystemGesture, AddressOf SystemGesture_Event theInkOverlay.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 InkOverlay 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 theInkOverlay.SetGestureStatus(theGesture, False) Next End Sub End Class
See Also