InkEditGestureEventHandler 委托

表示处理 InkEdit 控件的 Gesture 事件的方法。

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

语法

声明
Public Delegate Sub InkEditGestureEventHandler ( _
    sender As Object, _
    e As InkEditGestureEventArgs _
)
用法
Dim instance As New InkEditGestureEventHandler(AddressOf HandlerMethod)
public delegate void InkEditGestureEventHandler(
    Object sender,
    InkEditGestureEventArgs e
)
public delegate void InkEditGestureEventHandler(
    Object^ sender, 
    InkEditGestureEventArgs^ e
)
/** @delegate */
public delegate void InkEditGestureEventHandler(
    Object sender,
    InkEditGestureEventArgs e
)
JScript 不支持委托。

参数

备注

应用程序笔势 是应用程序中支持的笔势。

若要让此事件发生,则 InkEdit 控件必须具有对一组应用程序笔势的关注。若要设置 InkEdit 控件对一组笔势的关注,请调用 InkEdit 控件的 SetGestureStatus 方法。

有关特定应用程序笔势的列表,请参见 ApplicationGesture 枚举类型。有关应用程序笔势的更多信息,请参见Using GesturesCommand Input on the Tablet PC

创建 InkEditGestureEventHandler 委托时,需要标识将处理该事件的方法。若要将该事件与事件处理程序关联,请将该委托的一个实例添加到事件中。除非移除了该委托,否则每当发生该事件时就会调用此事件处理程序。

InkEdit 控件中,仅当笔势是自从最后一次调用 Recognize 方法或最后一次激发识别超时以来的第一个笔画时,才会引发 Gesture 事件。

如果取消 Gesture 事件,则为引发 Gesture 事件的 Stroke 对象引发 Stroke 事件。

InkEdit 控件不识别多笔画笔势。

InkEdit 控件对以下笔势有默认的关注和操作:

笔势

操作

左下,长左下

Enter

向右

空格

向左

Backspace

右上,长右上

Tab

若要更改笔势的默认操作:

示例

此示例演示如何订阅 Gesture 事件和 Stroke 事件,以扩充 ApplicationGesture 的功能。

激发 Gesture 事件时,它会检查 InkEdit 控件的笔势和当前状态。如果有必要,将修改笔势的行为,并取消该事件。

Private Sub mInkEdit_Gesture(ByVal sender As Object, ByVal e As InkEditGestureEventArgs)
    ' There might be more than one gesture passed in InkEditGestureEventArgs
    ' The gestures are arranged in order of confidence from most to least
    ' This event handler is only concerned with the first (most confident) gesture
    ' and only if the gesture is ApplicationGesture.Left with strong confidence
    Dim G As Gesture = e.Gestures(0)
    If (ApplicationGesture.Left = G.Id And RecognitionConfidence.Strong = G.Confidence) Then
        Dim pInkEdit As InkEdit = DirectCast(sender, InkEdit)
        ' by default, ApplicationGesture.Left maps to Backspace
        ' If the insertion point is at the beginning of the text
        ' and there is no text selected, then Backspace does not do anything.
        ' In this case, we will alter the gesture to map to Delete instead
        If (0 = pInkEdit.SelectionStart And 0 = pInkEdit.SelectionLength And pInkEdit.Text.Length > 0) Then
            ' take out the first character of the string
            pInkEdit.Text = pInkEdit.Text.Remove(0, 1)
            ' save the stroke ID in a class level var for use in the Stroke event
            Me.mStrokeID = e.Strokes(0).Id
            ' cancel the gesture so it won't perform the default action
            e.Cancel = True
        End If
    End If
End Sub
private void mInkEdit_Gesture(object sender, InkEditGestureEventArgs e)
{
    // There might be more than one gesture passed in InkEditGestureEventArgs
    // The gestures are arranged in order of confidence from most to least
    // This event handler is only concerned with the first (most confident) gesture
    // and only if the gesture is ApplicationGesture.Left with strong confidence
    Gesture G = e.Gestures[0];
    if (ApplicationGesture.Left == G.Id &&  RecognitionConfidence.Strong == G.Confidence)
    {
        InkEdit pInkEdit = (InkEdit)sender;

        // by default, ApplicationGesture.Left maps to Backspace
        // If the insertion point is at the beginning of the text
        // and there is no text selected, then Backspace does not do anything.
        // In this case, we will alter the gesture to map to Delete instead
        if (0 == pInkEdit.SelectionStart && 0 == pInkEdit.SelectionLength && pInkEdit.Text.Length > 0)
        {
            // take out the first character of the string
            pInkEdit.Text = pInkEdit.Text.Remove(0, 1);
            // save the stroke ID in a class level var for use in the Stroke event
            this.mStrokeID = e.Strokes[0].Id;
            // cancel the gesture so it won't perform the default action
            e.Cancel = true;
        }
    }
}

激发 Stroke 事件时,如果笔画是用于生成已在 Gesture 事件中修改其行为的笔势的那个笔画,则取消该事件。这将使笔画无法呈现。

Private Sub mInkEdit_Stroke(ByVal sender As Object, ByVal e As InkEditStrokeEventArgs)
    e.Cancel = (e.Stroke.Id = Me.mStrokeID)
End Sub
private void mInkEdit_Stroke(object sender, InkEditStrokeEventArgs e)
{
    e.Cancel = (e.Stroke.Id == this.mStrokeID);
}

平台

Windows Vista

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

版本信息

.NET Framework

受以下版本支持:3.0

另请参见

参考

Microsoft.Ink 命名空间

ApplicationGesture

InkEdit.SetGestureStatus

InkEdit.RecoTimeout