次の方法で共有


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 デリゲートを作成する場合は、イベントを処理するメソッドを指定します。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。

このイベントが発生するためには、InkEdit コントロールが一連のアプリケーション ジェスチャを待機している必要があります。InkEdit コントロールが一連のジェスチャを待機するように設定するには、InkEdit.SetGestureStatus メソッドを呼び出します。InkEdit コントロールは、複数ストローク ジェスチャを認識しません。

特定のアプリケーション ジェスチャについては、ApplicationGesture 列挙型を参照してください。アプリケーション ジェスチャの詳細については、「Using Gestures」および「Command Input on the Tablet PC」を参照してください。

InkEdit コントロールは、次のジェスチャを既定で待機し、そのジェスチャに対応するアクションを持ちます。

ジェスチャ

アクション

Down-left、Down-left-long

Enter

Right

Space

Left

BackSpace

Up-right、Up-right-long

Tab

InkEdit コントロールでは、Gesture イベントが発生するのは、Recognize メソッドを最後に呼び出して以降の最初のストロークによるジェスチャの場合、または認識タイムアウトが最後に発生して以降の最初のストロークによるジェスチャの場合に限られます。

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