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 不支援委派。
參數
- sender
型別:System.Object
這個事件的來源 RecognizerContext 物件。
- e
型別:Microsoft.Ink.RecognizerContextRecognitionEventArgs
包含事件資料的 RecognizerContextRecognitionEventArgs 物件。
備註
當 RecognizerContext 物件已經從 BackgroundRecognize 方法產生結果時,就會發生 Recognition 事件。
在建立 RecognizerContextRecognitionEventHandler 委派時,您要識別處理事件的方法。若要使事件與您的事件處理常式產生關聯,請將委派的執行個體加入至事件。除非您移除委派,否則每當事件發生時就會呼叫事件處理常式。
注意事項: |
---|
如果您嘗試從 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
請參閱
參考
RecognizerContext.BackgroundRecognize