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 委托时,需要标识将处理该事件的方法。若要将该事件与事件处理程序关联,请将该委托的一个实例添加到事件中。除非移除了该委托,否则每当发生该事件时就会调用此事件处理程序。

备注

如果尝试从 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