BackgroundRecognizeWithAlternates メソッドの呼び出し後に、RecognizerContext オブジェクトが結果を生成したときに発生します。
名前空間 : Microsoft.Ink
アセンブリ : Microsoft.Ink (Microsoft.Ink.dll 内)
構文
'宣言
Public Event RecognitionWithAlternates As RecognizerContextRecognitionWithAlternatesEventHandler
'使用
Dim instance As RecognizerContext
Dim handler As RecognizerContextRecognitionWithAlternatesEventHandler
AddHandler instance.RecognitionWithAlternates, handler
public event RecognizerContextRecognitionWithAlternatesEventHandler RecognitionWithAlternates
public:
event RecognizerContextRecognitionWithAlternatesEventHandler^ RecognitionWithAlternates {
void add (RecognizerContextRecognitionWithAlternatesEventHandler^ value);
void remove (RecognizerContextRecognitionWithAlternatesEventHandler^ value);
}
/** @event */
public void add_RecognitionWithAlternates (RecognizerContextRecognitionWithAlternatesEventHandler value)
/** @event */
public void remove_RecognitionWithAlternates (RecognizerContextRecognitionWithAlternatesEventHandler value)
JScript では、イベントは使用できません。
解説
イベント ハンドラは、このイベントについてのデータを格納している RecognizerContextRecognitionWithAlternatesEventArgs 型の引数を受け取ります。
RecognizerContextRecognitionWithAlternatesEventHandler デリゲートを作成する場合は、イベントを処理するメソッドを指定します。イベントをイベント ハンドラに関連付けるには、デリゲートのインスタンスをイベントに追加します。デリゲートを削除しない限り、そのイベントが発生すると常にイベント ハンドラが呼び出されます。
RecognitionWithAlternates イベント ハンドラから元の RecognizerContext オブジェクトへのアクセスを取得しようとすると、アプリケーション プログラミング インターフェイス (API) の動作は予測不可能になります。このようなことはしないでください。これを実行する必要がある場合は、代わりにフラグを作成して、Recognition イベント ハンドラに設定します。フラグを設定したら、そのフラグをポーリングすることで、イベント ハンドラの外部で 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_Stroke1)
' subscribe to the the RecognitionWithAlternates event.
' This event is fired when background recognition is complete,
' and recognition results (with alternates) are available
AddHandler mRecognizerContext.RecognitionWithAlternates, _
New RecognizerContextRecognitionWithAlternatesEventHandler(AddressOf mRecognizerContext_RecognitionWithAlternates)
// 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_Stroke1);
// subscribe to the the RecognitionWithAlternates event.
// This event is fired when background recognition is complete,
// and recognition results (with alternates) are available
mRecognizerContext.RecognitionWithAlternates +=
new RecognizerContextRecognitionWithAlternatesEventHandler(mRecognizerContext_RecognitionWithAlternates);
ユーザーがストロークを完了したことへの応答として Stroke イベントが発生するときに、新しく作成されたストロークが、RecognizerContext オブジェクトの Strokes コレクションに追加され、BackgroundRecognizeWithAlternates メソッドが呼び出されます。
Private Sub mInkOverlay_Stroke1(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.BackgroundRecognizeWithAlternates()
End Sub
private void mInkOverlay_Stroke1(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.BackgroundRecognizeWithAlternates();
}
バックグラウンドでの認識が完了すると、RecognitionWithAlternates イベントが発生します。このイベントの処理中に、認識の結果 (代替候補を含む) がリスト ボックスに配置されます。
' event fires when recognition results (with alternates) are ready
Private Sub mRecognizerContext_RecognitionWithAlternates(ByVal sender As Object, _
ByVal e As RecognizerContextRecognitionWithAlternatesEventArgs)
' 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 RecognizerContextRecognitionWithAlternatesEventHandler(AddressOf mRecognizerContext_RecognitionWithAlternates), _
New Object() {sender, e} _
)
Return
End If
If RecognitionStatus.NoError = e.RecognitionStatus Then
' show the top alternate
listBoxRecognitionResults.Items.Add("TOP:" + e.Result.TopAlternate.ToString())
' get the rest of the alternates
Dim allAlternates As RecognitionAlternates = e.Result.GetAlternatesFromSelection()
' show each of the other alternates
For Each oneAlternate As RecognitionAlternate In allAlternates
listBoxRecognitionResults.Items.Add("ALT:" + oneAlternate.ToString())
Next
End If
End Sub
// event fires when recognition results (with alternates) are ready
private void mRecognizerContext_RecognitionWithAlternates(object sender, RecognizerContextRecognitionWithAlternatesEventArgs 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 RecognizerContextRecognitionWithAlternatesEventHandler(mRecognizerContext_RecognitionWithAlternates),
new object[] { sender, e }
);
return;
}
if (RecognitionStatus.NoError == e.RecognitionStatus)
{
// show the top alternate
listBoxRecognitionResults.Items.Add("TOP:" + e.Result.TopAlternate.ToString());
// get the rest of the alternates
RecognitionAlternates allAlternates = e.Result.GetAlternatesFromSelection();
// show each of the other alternates
foreach (RecognitionAlternate oneAlternate in allAlternates)
{
listBoxRecognitionResults.Items.Add("ALT:" + oneAlternate.ToString());
}
}
}
プラットフォーム
Windows Vista
.NET Framework および .NET Compact Framework では、各プラットフォームのすべてのバージョンはサポートしていません。サポートされているバージョンについては、「.NET Framework システム要件」を参照してください。
バージョン情報
.NET Framework
サポート対象 : 3.0