InkPicture.CollectionMode 属性

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

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

语法

声明
<BrowsableAttribute(True)> _
Public Property CollectionMode As CollectionMode
用法
Dim instance As InkPicture
Dim value As CollectionMode

value = instance.CollectionMode

instance.CollectionMode = value
[BrowsableAttribute(true)]
public CollectionMode CollectionMode { get; set; }
[BrowsableAttribute(true)]
public:
property CollectionMode CollectionMode {
    CollectionMode get ();
    void set (CollectionMode value);
}
/** @property */
/** @attribute BrowsableAttribute(true) */
public CollectionMode get_CollectionMode()
/** @property */
/** @attribute BrowsableAttribute(true) */
public  void set_CollectionMode(CollectionMode value)
public function get CollectionMode () : CollectionMode
public function set CollectionMode (value : CollectionMode)

属性值

类型:Microsoft.Ink.CollectionMode
CollectionMode 值之一。

备注

备注

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

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

每个 CollectionMode 值对应的行为如下。

InkOnly 模式

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

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

GestureOnly 模式

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

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

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

  • 激发光标事件。

InkAndGesture 模式

  • 同时收集墨迹和笔势。

  • 仅识别单笔画笔势。

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

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

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

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

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

  1. 将 CollectionMode 属性设置为 InkAndGesture

  2. Stroke 事件中删除笔画。

  3. Gesture 事件中处理笔势。

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

示例

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

[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);
            }
        }
    }
}

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

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

平台

Windows Vista

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

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

InkPicture 类

InkPicture 成员

Microsoft.Ink 命名空间

CollectionMode

InkPicture.Stroke

InkPicture.Gesture

InkPicture.CursorDown

InkPicture.NewPackets

InkPicture.NewInAirPackets

InkPicture.SetGestureStatus