Share via


RecognizerContext.Recognition (Evento)

Actualización: noviembre 2007

Se produce cuando el objeto RecognizerContext ha generado los resultados a partir del método BackgroundRecognize.

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

Sintaxis

'Declaración
Public Event Recognition As RecognizerContextRecognitionEventHandler
'Uso
Dim instance As RecognizerContext
Dim handler As RecognizerContextRecognitionEventHandler

AddHandler instance.Recognition, handler
public event RecognizerContextRecognitionEventHandler Recognition
public:
 event RecognizerContextRecognitionEventHandler^ Recognition {
    void add (RecognizerContextRecognitionEventHandler^ value);
    void remove (RecognizerContextRecognitionEventHandler^ value);
}
/** @event */
public void add_Recognition (RecognizerContextRecognitionEventHandler value)
/** @event */
public void remove_Recognition (RecognizerContextRecognitionEventHandler value)
JScript no admite eventos.

Comentarios

El controlador de eventos recibe un argumento de tipo RecognizerContextRecognitionEventArgs que contiene datos sobre este evento.

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 a su controlador, a menos que se quite el delegado.

El comportamiento de la interfaz de programación de aplicaciones (API) es imprevisible si se intenta obtener acceso al objeto RecognizerContext original desde el controlador de eventos de reconocimiento. No intente realizar esta operación. Si necesita hacerlo, cree en su lugar un marcador y establézcalo en el controlador de eventos Recognition. A continuación, puede sondear el marcador para determinar cuándo cambiar las propiedades RecognizerContext fuera del controlador de eventos.

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

RecognizerContext (Clase)

RecognizerContext (Miembros)

Microsoft.Ink (Espacio de nombres)

RecognitionResult

RecognitionStatus

RecognizerContext.BackgroundRecognize

RecognizerContext.Recognize