RecognizerContext.RecognitionWithAlternates 事件
當 RecognizerContext 物件於呼叫 BackgroundRecognizeWithAlternates 方法後產生結果時發生。
命名空間: 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