InkCollector.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 InkCollector
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 InkCollector 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 recognizer 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 InkCollector object does not fire the following stroke and packet related events: the CursorDown, Stroke, NewPackets, and NewInAirPackets events.
Cursor events fire.
Ink is always deleted.
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 InkCollector object's OnGesture event handler is invoked. To cancel the gesture, set the inherited Cancel property of the InkCollectorGestureEventArgs object to true. Canceling the gesture forces the InkCollector 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 InkCollector object's interest in a known gesture is set (by calling the SetGestureStatus method). If you draw ink similar to the known gesture and the known gesture is in the recognizer's list of alternates, the Gesture event fires, causing the ink to disappear, 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: it 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():
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(InkCollector theInkCollector)
{
ApplicationGesture test = ApplicationGesture.NoGesture;
Array theGestures = System.Enum.GetValues(test.GetType());
foreach (ApplicationGesture theGesture in theGestures)
{
theInkCollector.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 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 our 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
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
InkCollector Class
InkCollector Members
Microsoft.Ink Namespace
InkCollector.Enabled
InkCollector.CollectingInk
CollectionMode