Share via


RecognizerContextRecognitionEventHandler (Delegado)

Actualización: noviembre 2007

Representa el método que controla el evento Recognition de un objeto RecognizerContext.

Espacio de nombres:  Microsoft.Ink
Ensamblado:  Microsoft.Ink (en Microsoft.Ink.dll)

Sintaxis

'Declaración
Public Delegate Sub RecognizerContextRecognitionEventHandler ( _
    sender As Object, _
    e As RecognizerContextRecognitionEventArgs _
)
'Uso
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 no admite delegados.

Parámetros

Comentarios

El evento Recognition se produce cuando el objeto RecognizerContext ha generado los resultados a partir del método BackgroundRecognize.

Cuando se crea un delegado de RecognizerContextRecognitionEventHandler, se identifica el método que controla el evento. Para asociarlo al controlador de eventos, se debe agregar al evento una instancia del delegado. Siempre que se produce el evento se llama al controlador de eventos, a menos que se quite el delegado.

Nota

Si intenta obtener acceso al objeto RecognizerContext original del delegado de RecognizerContextRecognitionEventHandler, el comportamiento puede ser imprevisible. No intente realizar esta operación.

Ejemplos

En este ejemplo, cada trazo creado en un objeto InkOverlay se reconoce automáticamente y se muestra el resultado del reconocimiento.

Durante el inicio de la aplicación, se crea una instancia del objeto RecognizerContext y se asignan controladores de eventos.

' 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);

Cuando se activa el evento Stroke (en respuesta a la finalización de un trazo por parte del usuario), el trazo recién creado se agrega a la colección Strokes del objeto RecognizerContext y se llama al método 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();
}

Cuando se completa el reconocimiento en segundo plano, se desencadena el evento Recognition. Durante el control de este evento, los resultados del reconocimiento se colocan en un cuadro de lista.

' 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);
    }
}

Plataformas

Windows Vista

.NET Framework y .NET Compact Framework no admiten todas las versiones de cada plataforma. Para obtener una lista de las versiones compatibles, vea Requisitos de sistema de .NET Framework.

Información de versión

.NET Framework

Compatible con: 3.0

Vea también

Referencia

Microsoft.Ink (Espacio de nombres)

RecognizerContext.BackgroundRecognize

RecognitionResult

RecognizerContextRecognitionEventArgs.RecognitionStatus

RecognizerContext.Recognize