共用方式為


InkEdit.Gesture 事件

發生於辨識「應用程式筆勢」時。

命名空間:  Microsoft.Ink
組件:  Microsoft.Ink (在 Microsoft.Ink.dll 中)

語法

'宣告
Public Event Gesture As InkEditGestureEventHandler
'用途
Dim instance As InkEdit
Dim handler As InkEditGestureEventHandler

AddHandler instance.Gesture, handler
public event InkEditGestureEventHandler Gesture
public:
 event InkEditGestureEventHandler^ Gesture {
    void add (InkEditGestureEventHandler^ value);
    void remove (InkEditGestureEventHandler^ value);
}
/** @event */
public void add_Gesture (InkEditGestureEventHandler value)
/** @event */
public void remove_Gesture (InkEditGestureEventHandler value)
JScript 不支援事件。

備註

事件處理常式會收到 InkEditGestureEventArgs 型別的引數,其中包含這個事件的相關資料。

在建立 InkEditGestureEventHandler 委派 (Delegate) 時,您會識別處理事件的方法。若要使事件與您的事件處理常式產生關聯,請將委派的執行個體 (Instance) 加入至事件。除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。

為了讓這個事件發生,InkEdit 控制項必須與一組應用程式筆勢有關聯。若要設定 InkEdit 控制項與一組筆勢的關聯,請呼叫 InkEdit.SetGestureStatus 方法。InkEdit 控制項不會辨識多個筆劃筆勢。

如需特定的應用程式筆勢清單,請參閱 ApplicationGesture 列舉型別。如需應用程式筆勢的詳細資訊,請參閱Using GesturesCommand Input on the Tablet PC

InkEdit 控制項具有下列事件的預設關聯與動作:

筆勢

動作

向左下、向左下拉長

ENTER

向右

空格鍵

向左

退格鍵

向右上、向右上拉長

TAB

InkEdit 控制項中,只有當筆勢是在上次呼叫 Recognize 方法或上次引發辨識逾時之後的第一個筆劃時,才會引發 Gesture 事件。

如果取消 Gesture 事件,則會針對引發 Gesture 事件的 Stroke 物件引發 Stroke 事件。

若要改變筆勢的預設動作

  • 加入 Gesture 和 Stroke 事件的事件處理常式。

  • 在 Gesture 事件處理常式中,取消筆勢的 Gesture 事件,然後執行筆勢的「替代」動作。

  • Stroke 事件處理常式中,針對引發已取消之 Gesture 事件的 Stroke 物件,取消 Stroke 事件。

範例

這個範例示範如何訂閱 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

請參閱

參考

InkEdit 類別

InkEdit 成員

Microsoft.Ink 命名空間

InkEditGestureEventArgs

ApplicationGesture

InkEdit.SetGestureStatus

InkEdit.RecoTimeout