Condividi tramite


Evento RecognizerContext.RecognitionWithAlternates

Aggiornamento: novembre 2007

Viene generato quando l'oggetto RecognizerContext ha creato risultati dopo aver chiamato il metodo BackgroundRecognizeWithAlternates.

Spazio dei nomi:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Sintassi

'Dichiarazione
Public Event RecognitionWithAlternates As RecognizerContextRecognitionWithAlternatesEventHandler
'Utilizzo
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 non supporta gli eventi.

Note

Il gestore eventi riceve un argomento di tipo RecognizerContextRecognitionWithAlternatesEventArgs contenente i dati relativi a questo evento.

Quando si crea un delegato RecognizerContextRecognitionWithAlternatesEventHandler, si identifica il metodo che gestisce l'evento. Per associare l'evento al gestore eventi in uso, aggiungere all'evento un'istanza del delegato. Il gestore eventi viene chiamato ogni volta che si verifica l'evento, a meno che non venga rimosso il delegato.

Il comportamento dell'API è imprevedibile se si tenta di accedere all'oggetto RecognizerContext originale dal gestore eventi RecognitionWithAlternates. Non tentare di eseguire questa operazione. In caso contrario, se è necessario eseguirla, creare un flag e impostarlo nel gestore eventi Recognition. Successivamente, è possibile eseguire il polling di tale flag per determinare il momento in cui modificare le proprietà RecognizerContext all'esterno del gestore eventi.

Esempi

In questo esempio viene riconosciuto automaticamente ogni tratto eseguito in un oggetto InkOverlay e vengono visualizzati i risultati del riconoscimento (incluse le alternative).

All'avvio dell'applicazione, viene creata un'istanza dell'oggetto RecognizerContext e vengono assegnati i gestori eventi.

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

Quando viene generato l'evento Stroke (in risposta al completamento di un tratto da parte dell'utente), il tratto appena creato viene aggiunto all'insieme Strokes dell'oggetto RecognizerContext e viene chiamato il metodo 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();
}

Al termine del riconoscimento in background, viene generato l'evento RecognitionWithAlternates. Durante la gestione di questo evento, i risultati del riconoscimento (incluse le alternative) vengono collocati in una casella di riepilogo.

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

Piattaforme

Windows Vista

.NET Framework e .NET Compact Framework non supportano tutte le versioni di ciascuna piattaforma. Per un elenco delle versioni supportate, vedere Requisiti di sistema di .NET Framework.

Informazioni sulla versione

.NET Framework

Supportato in: 3.0

Vedere anche

Riferimenti

RecognizerContext Classe

Membri RecognizerContext

Spazio dei nomi Microsoft.Ink

RecognitionResult

RecognizerContext.BackgroundRecognizeWithAlternates

RecognizerContext.Recognize