Compartir a través de


RecognizerContext.RecognitionWithAlternates (Evento)

Actualización: noviembre 2007

Se produce cuando el objeto RecognizerContext ha generado los resultados después de llamar al método BackgroundRecognizeWithAlternates.

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

Sintaxis

'Declaración
Public Event RecognitionWithAlternates As RecognizerContextRecognitionWithAlternatesEventHandler
'Uso
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 no admite eventos.

Comentarios

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

Cuando se crea un delegado de RecognizerContextRecognitionWithAlternatesEventHandler, 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 RecognitionWithAlternates. 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 muestran los resultados del reconocimiento, incluidas las alternativas.

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

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

Cuando se completa el reconocimiento en segundo plano, se desencadena el evento RecognitionWithAlternates. Durante el control de este evento, los resultados del reconocimiento (incluidas las alternativas) se introducen en un cuadro de lista.

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

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

RecognizerContext.BackgroundRecognizeWithAlternates

RecognizerContext.Recognize