InkOverlay.CollectionMode Property
Gets or sets the collection mode that determines whether ink, gesture, or both are recognized as the user writes.
Namespace: Microsoft.Ink
Assembly: Microsoft.Ink (in microsoft.ink.dll)
Syntax
'Declaration
Public Property CollectionMode As CollectionMode
'Usage
Dim instance As InkOverlay
Dim value As CollectionMode
value = instance.CollectionMode
instance.CollectionMode = value
public CollectionMode CollectionMode { get; set; }
public:
property CollectionMode CollectionMode {
CollectionMode get ();
void set (CollectionMode value);
}
/** @property */
public CollectionMode get_CollectionMode ()
/** @property */
public void set_CollectionMode (CollectionMode value)
public function get CollectionMode () : CollectionMode
public function set CollectionMode (value : CollectionMode)
Not applicable.
Property Value
The CollectionMode that determines whether ink, gesture, or both are recognized as the user writes.
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 GestureOnly 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.
Example
This C# example displays gesture event information in the status bar of the main form window. Starting with a generic generated application, add a StatusBarStatusBar 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);
}
}
}
}
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 StatusBarStatusBar 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
Platforms
Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.
Version Information
.NET Framework
Supported in: 3.0
See Also
Reference
InkOverlay Class
InkOverlay Members
Microsoft.Ink Namespace
InkOverlay.Enabled
InkOverlay.CollectingInk
CollectionMode