Compartir a través de


RecognizerContextRecognitionWithAlternatesEventHandler (Delegado)

Actualización: noviembre 2007

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

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

Sintaxis

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

Parámetros

Comentarios

El evento RecognitionWithAlternates se produce cuando el objeto RecognizerContext genera los resultados después de llamar al método BackgroundRecognizeWithAlternates.

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 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 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

Microsoft.Ink (Espacio de nombres)

RecognizerContext.BackgroundRecognizeWithAlternates

RecognitionResult

RecognizerContext.Recognize