RecognitionResult.SetResultOnStrokes Method

RecognitionResult.SetResultOnStrokes Method

Assigns the RecognitionResult object to the Strokes collection that was used to generate the results.

Definition

Visual Basic .NET Public Sub SetResultOnStrokes()
C# public void SetResultOnStrokes();
Managed C++ public: void SetResultOnStrokes();

Remarks

System performance suffers if recognition results are automatically assigned to every Strokes collection. Therefore results are not attached to a Strokes collection by default. To assign results to a Strokes collection, you must call the SetResultOnStrokes method. To return the recognition results for a Strokes collection, use the RecognitionResult property of the Strokes collection. After you assign results to a Strokes collection, you can then store the strokes in a CustomStrokes collection. These custom strokes, as well as the RecognitionResult, can be persisted and retrieved for later use.

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