RecognizerContextRecognitionWithAlternatesEventHandler 委托
表示处理 RecognizerContext 对象的 RecognitionWithAlternates 事件的方法。
命名空间: Microsoft.Ink
程序集: Microsoft.Ink(在 Microsoft.Ink.dll 中)
语法
声明
Public Delegate Sub RecognizerContextRecognitionWithAlternatesEventHandler ( _
sender As Object, _
e As RecognizerContextRecognitionWithAlternatesEventArgs _
)
用法
Dim instance As New RecognizerContextRecognitionWithAlternatesEventHandler(AddressOf HandlerMethod)
public delegate void RecognizerContextRecognitionWithAlternatesEventHandler(
Object sender,
RecognizerContextRecognitionWithAlternatesEventArgs e
)
public delegate void RecognizerContextRecognitionWithAlternatesEventHandler(
Object^ sender,
RecognizerContextRecognitionWithAlternatesEventArgs^ e
)
/** @delegate */
public delegate void RecognizerContextRecognitionWithAlternatesEventHandler(
Object sender,
RecognizerContextRecognitionWithAlternatesEventArgs e
)
JScript 不支持委托。
参数
- sender
类型:System.Object
此事件的源 RecognizerContext 对象。
- e
类型:Microsoft.Ink.RecognizerContextRecognitionWithAlternatesEventArgs
包含事件数据的 RecognizerContextRecognitionWithAlternatesEventArgs 对象。
备注
如果 RecognizerContext 在调用 BackgroundRecognizeWithAlternates 方法之后产生结果,则会发生 RecognitionWithAlternates 事件。
创建 RecognizerContextRecognitionWithAlternatesEventHandler 委托时,需要标识将处理该事件的方法。若要将该事件与事件处理程序关联,请将该委托的一个实例添加到事件中。除非移除了该委托,否则每当发生该事件时就会调用此事件处理程序。
备注
如果尝试从 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_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