Freigeben über


InkPicture.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 InkPicture
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

One of the CollectionMode values.

Remarks

Note

The InkPicture control 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 InkPicture control 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 InkPicture control'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 InkPicture control 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 InkPicture control'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 alternate, 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:

  1. Set the CollectionMode property to InkAndGesture.

  2. In the Stroke event, delete the stroke.

  3. In the Gesture event, process the gesture.

  4. 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, and an InkPicture control, theInkPicture, to the main form and the following code.

[C#]

//...
using Microsoft.Ink;

namespace CollectionMode_CS
{
    public class CollectionModeForm : System.Windows.Forms.Form
    {
        // ... The generated code will be here.
        //Add this code following the implementation of Main():

        private void CollectionModeForm_Load(object sender, System.EventArgs e)
        {
            // Initialize the InkPicture object.
            theInkPicture.CollectionMode = CollectionMode.InkAndGesture;
            ClearAppGestures();

            // Turn on interest in the ChevronDown application gesture.
            theInkPicture.SetGestureStatus(ApplicationGesture.ChevronDown, true);
            theInkPicture.SetGestureStatus(ApplicationGesture.ChevronUp, true);
            theInkPicture.Gesture += new InkCollectorGestureEventHandler(theInkPicture_Gesture);
            theInkPicture.SystemGesture +=
            new InkCollectorSystemGestureEventHandler(theInkPicture_SystemGesture);
            theInkPicture.Enabled = true;
        }

        private void theInkPicture_Gesture(object sender,
            Microsoft.Ink.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 theInkPicture_SystemGesture(object sender,
            Microsoft.Ink.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)
            {
               theInkPicture.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, and an InkPicture control, theInkPicture, to the main form and the following code.

Imports Microsoft.Ink

Public Class CollectionModeForm
    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, and an InkPicture control, the InkPicture.
#End Region

    Private Sub CollectionModeForm_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load
        'Set the InkPicture to collect both ink and gestures.
        theInkPicture.CollectionMode = CollectionMode.InkAndGesture
        'Clear interest in all of the application gestures
        ClearAppGestures()
        'Set our interest in only two gestures.
        theInkPicture.SetGestureStatus(ApplicationGesture.ChevronDown, True)
        theInkPicture.SetGestureStatus(ApplicationGesture.ChevronUp, True)
        'Add the handlers for application and system gestures.
        AddHandler theInkPicture.Gesture, AddressOf theInkPicture_Gesture
        AddHandler theInkPicture.SystemGesture, AddressOf theInkPicture_SystemGesture
        theInkPicture.Enabled = True
    End Sub

    Private Sub theInkPicture_Gesture(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 theInkPicture_SystemGesture( _
        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 InkPicture 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
            theInkPicture.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

InkPicture Class
InkPicture Members
Microsoft.Ink Namespace
CollectionMode
InkPicture.Stroke
InkPicture.Gesture
InkPicture.CursorDown
InkPicture.NewPackets
InkPicture.NewInAirPackets
InkPicture.SetGestureStatus