Share via


InkCollector.CollectionMode 属性

获取或设置收集模式,该模式确定是否将墨迹 和/或笔势 识别为用户写入。

命名空间:  Microsoft.Ink
程序集:  Microsoft.Ink(在 Microsoft.Ink.dll 中)

语法

声明
Public Property CollectionMode As CollectionMode
用法
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)

属性值

类型:Microsoft.Ink.CollectionMode
CollectionMode ,用于确定是否将墨迹和/或笔势识别为用户写入。

备注

备注

如果试图在收集墨迹时更改 CollectionMode 属性,则 InkCollector 对象将生成错误。若要避免这种冲突,请在更改 CollectionMode 属性之前检查 CollectingInk 属性。

有关可用模式的列表,请参见 CollectionMode 枚举。但是,如果在安装了 Tablet PC SDK 但未安装识别器 的系统上使用 CollectionMode 属性,该模式无法设置为 GestureOnlyInkAndGesture

每个 CollectionMode 值的行为如下。

InkOnly 模式

  • 仅收集墨迹;不收集笔势。

  • Gesture 事件关注设置为 false(所有其他事件关注保持不变)。

GestureOnly 模式

  • 仅收集笔势;不收集墨迹。笔画发送到笔势识别器之后将被删除。

  • Gesture 事件关注设置为 true(所有其他事件关注保持不变)。

  • InkCollector 对象不会激发以下与笔画和数据包相关的事件:CursorDownStrokeNewPacketsNewInAirPackets 事件。

  • 激发光标事件。

  • 始终删除墨迹。

InkAndGesture 模式

  • 同时收集墨迹和笔势。

  • 仅识别单笔画笔势。

  • Gesture 事件关注设置为 true(所有其他事件关注保持不变)。

  • Gesture 事件首先激发,这样,在调用 InkCollector 对象的 OnGesture 事件处理程序时,您可以接受或取消笔势。若要取消笔势,请将 InkCollectorGestureEventArgs 对象的继承的 Cancel 属性设置为 true。取消笔势将强制 InkCollector 对象收集墨迹。

更改收集模式不会改变各笔势的状态。

如果 CollectionMode 属性设置为 InkAndGesture,并且将 InkCollector 对象设置为关注某个已知笔势(通过调用 SetGestureStatus 方法),则会发生意外的行为。如果绘制与已知笔势相似的墨迹,并且该已知笔势在识别器的备选项 列表中,则会激发 Gesture 事件,从而导致墨迹消失,即使该笔势不是最佳备选项也是如此。若要防止墨迹在希望收集墨迹而不是笔势时消失,请取消笔势收集,并将 InkCollectorGestureEventArgs 对象的继承的 Cancel 属性设置为 true。

如果 CollectionMode 属性设置为 GestureOnly,则从用户添加笔势到发生 Gesture 事件之间的超时是一个固定值:它不能以编程方式更改。在 InkAndGesture 模式中,笔势识别的速度更快。若要在 InkAndGesture 模式下仅收集笔势并禁止收集墨迹,您可以:

将 CollectionMode 属性设置为 InkAndGesture

  1. Stroke 事件中删除笔画。

  2. Gesture 事件中处理笔势。

  3. DynamicRendering 设置为 false 可以在笔势处理时禁止墨迹流。

示例

此 C# 示例在主窗体窗口的状态栏中显示笔势事件信息。从常规生成的应用程序开始,将 StatusBar 控件 statusBar1 添加到主窗体中,并添加以下代码。

//...
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);
            }
        }
    }
}

此 Microsoft Visual Basic .NET 示例在主窗体窗口的状态栏中显示笔势事件信息。从常规生成的应用程序开始,将 StatusBar 控件 statusBar1 添加到主窗体中,并添加以下代码。

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

平台

Windows Vista

.NET Framework 和 .NET Compact Framework 并不是对每个平台的所有版本都提供支持。有关支持的版本的列表,请参见.NET Framework 系统要求

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

InkCollector 类

InkCollector 成员

Microsoft.Ink 命名空间

InkCollector.Enabled

InkCollector.CollectingInk

CollectionMode