Compartilhar via


RecognitionResult.ModifyTopAlternate Method

RecognitionResult.ModifyTopAlternate Method

Modifies the RecognitionResult object with a known RecognitionAlternate object.

Definition

Visual Basic .NET Public Sub ModifyTopAlternate( _
ByVal alternate As RecognitionAlternate _
)
C# public void ModifyTopAlternate(
RecognitionAlternate alternate
);
Managed C++ public: void ModifyTopAlternate(
RecognitionAlternate *alternate
);

Parameters

alternate Microsoft.Ink.RecognitionAlternate. The RecognitionAlternate object to use to modify the RecognitionResult object.

Exceptions

COMException Leave Site:
InvalidOperationException Leave Site:

Remarks

By default, the TopString property of the RecognitionResult object corresponds to the TopAlternate property; however, you can use this method to use alternates other than the top alternate in the result. When you choose an alternate other than the top alternate, you are essentially choosing a different path through the lattice of alternates that are associated with the results.

To retrieve the RecognitionAlternate objects that can be used to modify the RecognitionResult object, call the GetAlternatesFromSelection method.

The alternate used in this method can be a word alternate within an entire sentence. For example, calling the ModifyTopAlternate method on an alternate obtained by calling GetAlternatesFromSelection(0,5) for "Hello World" changes "Hello" and leaves "World" unaltered.

Note: A call to the ModifyTopAlternate method may modify the TopString and TopAlternate properties of the RecognitionResult object.

Examples

[C#]

This C# example tracks the RecognitionResult object and its RecognitionAlternate objects. The example then saves the RecognitionResult objects with the Stroke objects that are recognized by using the SetResultOnStrokes method. Finally, the example modifies the TopAlternate property of the RecognitionResult object based on user input.

// Declarations...
InkCollector theInkCollector;
Strokes theStrokes;
RecognizerContext theRecognizerContext;
RecognitionResult theRecognitionResult;

// Initialization...

// Initialize the recognizer's strokes
// and assign them to the context.
theStrokes = theInkCollector.Ink.Strokes;
theRecognizerContext = new RecognizerContext();
theRecognizerContext.Strokes = theStrokes;

// Install event handlers.
theRecognizerContext.RecognitionWithAlternates +=
    new RecognizerContextRecognitionWithAlternatesEventHandler(
        RecognitionWithAlternates_Event);

//...

// Recognition Event Handler
private void RecognitionWithAlternates_Event(
    object sender,
    RecognizerContextRecognitionWithAlternatesEventArgs e)
{
    // Save the RecognitionResult, and copy it to the strokes
    theRecognitionResult = e.Result;
    theRecognitionResult.SetResultOnStrokes();
}

// Modify the TopAlternate of the result
private void buttonAlt2_Click(object sender, System.EventArgs e)
{
    RecognitionAlternates theRecognitionAlternates =
        theRecognitionResult.GetAlternatesFromSelection(0, -1);
    theRecognitionResult.ModifyTopAlternate(theRecognitionAlternates[2]);
}

[Visual Basic .NET]

This Microsoft® Visual Basic® .NET example tracks the RecognitionResult object and its RecognitionAlternate objects. The example then saves the RecognitionResult objects with the Stroke objects that are recognized by using the SetResultOnStrokes method. Finally, the example modifies the TopAlternate property of the RecognitionResult object based on user input.

'Declarations...
Dim theInkCollector As InkCollector
Dim theStrokes As Strokes
Dim theRecognizerContext As RecognizerContext
Dim theRecognitionResult As RecognitionResult

'Initialization...

'Initialize the recognizer's strokes
'and assign them to the context.
theStrokes = theInkCollector.Ink.Strokes
theRecognizerContext = new RecognizerContext()
theRecognizerContext.Strokes = theStrokes

'Install event handlers.
AddHandler theRecognizerContext.RecognitionWithAlternates, _
AddressOf RecognitionWithAlternates_Event

'...

'Recognition Event Handler
Private Sub RecognitionWithAlternates_Event( _
ByVal sender As Object, _
ByVal e As RecognizerContextRecognitionWithAlternatesEventArgs)
    'Save the RecognitionResult, and copy it to the strokes.
    theRecognitionResult = e.Result
    theRecognitionResult.SetResultOnStrokes()
End Sub

'Modify the TopAlternate of the result
Private Sub ButtonAlt2_Click(object sender, System.EventArgs e) _
Handles ButtonAlt2.Click
    RecognitionAlternates theRecognitionAlternates =
        theRecognitionResult.GetAlternatesFromSelection(0, -1)
    theRecognitionResult.ModifyTopAlternate(theRecognitionAlternates(2))
End Sub

See Also