Partager via


RecognizerContext.BackgroundRecognizeWithAlternates, méthode

Mise à jour : November 2007

Entraîne la reconnaissance par l'objet Recognizer de la collection Strokes associée et le déclenchement d'un événement RecognitionWithAlternates, avec les données d'application associées, lorsque la reconnaissance est terminée.

Espace de noms :  Microsoft.Ink
Assembly :  Microsoft.Ink (dans Microsoft.Ink.dll)

Syntaxe

'Déclaration
Public Sub BackgroundRecognizeWithAlternates
'Utilisation
Dim instance As RecognizerContext

instance.BackgroundRecognizeWithAlternates()
public void BackgroundRecognizeWithAlternates()
public:
void BackgroundRecognizeWithAlternates()
public void BackgroundRecognizeWithAlternates()
public function BackgroundRecognizeWithAlternates()

Notes

Cette méthode spécifie que la reconnaissance de l'écriture manuscrite est effectuée de façon asynchrone.

Pour exécuter une reconnaissance qui inclut uniquement la meilleure proposition de substitution, appelez la méthode BackgroundRecognize.

L'événement RecognitionWithAlternates n'est pas déclenché si le module de reconnaissance ne reconnaît aucune proposition de substitution.

Exemples

Dans cet exemple, chaque trait dessiné dans un objet InkOverlay est reconnu automatiquement et les résultats de reconnaissance (y compris les propositions de substitution) sont affichés.

Pendant le démarrage de l'application, l'objet RecognizerContext est instancié et les gestionnaires d'événements sont assignés.

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

Lorsque l'événement Stroke se déclenche (suite à la création d'un trait), le nouveau trait est ajouté à la collection Strokes de l'objet RecognizerContext, et la méthode BackgroundRecognizeWithAlternates est appelée.

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

Lorsque la reconnaissance d'arrière-plan est terminée, l'événement RecognitionWithAlternates se déclenche. Pendant la gestion de cet événement, les résultats de la reconnaissance (y compris les propositions de substitution) sont placés dans une zone de liste.

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

Plateformes

Windows Vista

Le .NET Framework et le .NET Compact Framework ne prennent pas en charge toutes les versions de chaque plateforme. Pour obtenir la liste des versions prises en charge, consultez Configuration requise du .NET Framework.

Informations de version

.NET Framework

Pris en charge dans : 3.0

Voir aussi

Référence

RecognizerContext, classe

Membres RecognizerContext

BackgroundRecognizeWithAlternates, surcharge

Microsoft.Ink, espace de noms

BackgroundRecognizeWithAlternates

RecognizerContext.BackgroundRecognize

ExtendedProperty.Data

RecognitionAlternate