次の方法で共有


RecognizerContextRecognitionEventHandler デリゲート

RecognizerContext オブジェクトの Recognition イベントを処理するメソッドを表します。

名前空間 :  Microsoft.Ink
アセンブリ :  Microsoft.Ink (Microsoft.Ink.dll 内)

構文

'宣言
Public Delegate Sub RecognizerContextRecognitionEventHandler ( _
    sender As Object, _
    e As RecognizerContextRecognitionEventArgs _
)
'使用
Dim instance As New RecognizerContextRecognitionEventHandler(AddressOf HandlerMethod)
public delegate void RecognizerContextRecognitionEventHandler(
    Object sender,
    RecognizerContextRecognitionEventArgs e
)
public delegate void RecognizerContextRecognitionEventHandler(
    Object^ sender, 
    RecognizerContextRecognitionEventArgs^ e
)
/** @delegate */
public delegate void RecognizerContextRecognitionEventHandler(
    Object sender,
    RecognizerContextRecognitionEventArgs e
)
JScript では、デリゲートは使用できません。

パラメータ

解説

Recognition イベントは、RecognizerContext オブジェクトが BackgroundRecognize メソッドから結果を生成したときに発生します。

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

ms552551.alert_note(ja-jp,VS.90).gifメモ :

RecognizerContextRecognitionEventHandler デリゲートから元の RecognizerContext オブジェクトにアクセスしようとすると、予測不可能な動作が起きます。このようなことはしないでください。

この例では、InkOverlay オブジェクトで作成された各ストロークが自動的に認識され、認識結果が表示されます。

アプリケーションの起動中に、RecognizerContext オブジェクトがインスタンス化され、イベント ハンドラが割り当てられます。

' create a new RecognizerContext object
' the object's Strokes property is initialized to null
mRecognizerContext = New RecognizerContext()
' assign the Strokes property by creating a fresh Strokes collection 
mRecognizerContext.Strokes = mInkOverlay.Ink.CreateStrokes()
' subscribe to the Strokes event. It is during this event
' that we can add strokes to the RecognizerContext
AddHandler mInkOverlay.Stroke, New InkCollectorStrokeEventHandler(AddressOf mInkOverlay_Stroke2)
' subscribe to the the Recognition event. 
' This event is fired when background recognition is complete, 
' and recognition results (without alternates) are available
AddHandler mRecognizerContext.Recognition, _
        New RecognizerContextRecognitionEventHandler(AddressOf mRecognizerContext_Recognition)
// create a new RecognizerContext object
// the object's Strokes property is initialized to null
mRecognizerContext = new RecognizerContext();
// assign the Strokes property by creating a fresh Strokes collection 
mRecognizerContext.Strokes = mInkOverlay.Ink.CreateStrokes();
// subscribe to the Strokes event. It is during this event
// that we can add strokes to the RecognizerContext
mInkOverlay.Stroke += new InkCollectorStrokeEventHandler(mInkOverlay_Stroke2);
// subscribe to the the Recognition event. 
// This event is fired when background recognition is complete, 
// and recognition results (without alternates) are available
mRecognizerContext.Recognition += 
    new RecognizerContextRecognitionEventHandler(mRecognizerContext_Recognition);

ユーザーがストロークを完了したことへの応答として Stroke イベントが発生するときに、新しく作成されたストロークが、RecognizerContext オブジェクトの Strokes コレクションに追加され、BackgroundRecognize メソッドが呼び出されます。

Private Sub mInkOverlay_Stroke2(ByVal sender As Object, ByVal e As InkCollectorStrokeEventArgs)
    ' in case background recognition is still occurring, stop it
    mRecognizerContext.StopBackgroundRecognition()
    ' add the stroke, and start recognition
    mRecognizerContext.Strokes.Add(e.Stroke)
    mRecognizerContext.BackgroundRecognize()
End Sub
private void mInkOverlay_Stroke2(object sender, InkCollectorStrokeEventArgs e)
{
    // in case background recognition is still occurring, stop it
    mRecognizerContext.StopBackgroundRecognition();
    // add the stroke, and start recognition
    mRecognizerContext.Strokes.Add(e.Stroke);
    mRecognizerContext.BackgroundRecognize();
}

バックグラウンドでの認識が完了すると、Recognition イベントが発生します。このイベントの処理中に、認識の結果がリスト ボックスに配置されます。

' event fires when recognition results (without alternates) are ready
Private Sub mRecognizerContext_Recognition(ByVal sender As Object, _
            ByVal e As RecognizerContextRecognitionEventArgs)
    ' when updating a control, must use Invoke() since controls are
    ' not thread safe and recognition occurs on a different thread
    If Me.InvokeRequired Then
        ' recursively call this method via Invoke()
        Me.Invoke( _
            New RecognizerContextRecognitionEventHandler(AddressOf mRecognizerContext_Recognition), _
            New Object() {sender, e} _
        )
        Return
    End If
    If RecognitionStatus.NoError = e.RecognitionStatus Then
        listBoxRecognitionResults.Items.Add(e.Text)
    End If
End Sub
// event fires when recognition results (without alternates) are ready
private void mRecognizerContext_Recognition(object sender, RecognizerContextRecognitionEventArgs e)
{
    // when updating a control, must use Invoke() since controls are
    // not thread safe and recognition occurs on a different thread
    if (this.InvokeRequired)
    {
        // recursively call this method via Invoke()
        this.Invoke(
            new RecognizerContextRecognitionEventHandler(mRecognizerContext_Recognition), 
            new object[] { sender, e }
            );
        return;
    }
    if (RecognitionStatus.NoError == e.RecognitionStatus)
    {
        listBoxRecognitionResults.Items.Add(e.Text);
    }
}

プラットフォーム

Windows Vista

.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。

バージョン情報

.NET Framework

サポート対象 : 3.0

参照

参照

Microsoft.Ink 名前空間

RecognizerContext.BackgroundRecognize

RecognitionResult

RecognizerContextRecognitionEventArgs.RecognitionStatus

RecognizerContext.Recognize