Compartir a través de


RecognizerContext.Recognize Method

RecognizerContext.Recognize Method

Returns a RecognitionResult object for a Strokes collection.

Definition

Visual Basic .NET Public Function Recognize( _
ByRef recognitionStatus As RecognitionStatus _
) As RecognitionResult
C# public RecognitionResult Recognize(
out RecognitionStatus recognitionStatus
);
Managed C++ public: RecognitionResult* Recognize(
RecognitionStatus **recognitionStatus
);

Parameters

> > >
recognitionStatus Microsoft.Ink.RecognitionStatus. A member of the RecognitionStatus enumeration that indicates whether an error occurred during recognition and, if so, which error occurred.

NoError0 Indicates no errors occurred.
Interrupted1 Indicates the recognition was interrupted by a call to StopBackgroundRecognition.
ProcessFailed2 Indicates the ink recognition process failed.
InkAddedFailed4 Indicates the ink could not be added.
SetAutoCompletionModeFailed8 Indicates the character Autocomplete mode could not be set.
SetStrokesFailed16 Indicates the strokes could not be set.
SetGuideFailed32 Indicates the recognition guide could not be set.
SetFlagsFailed64 Indicates the flags could not be set.
SetFactoidFailed128 Indicates the factoid could not be set.
SetPrefixSuffixFailed256 Indicates the suffix or the prefix could not be set.
SetWordListFailed512 Indicates the word list could not be set.

Return Value

Microsoft.Ink.RecognitionResult. The RecognitionResult object for a recognized Strokes collection.

Exceptions

COMException Leave Site:
ObjectDisposedException Leave Site: The RecognizerContext object is disposed.

Remarks

This method returns null (Nothing in Microsoft® Visual Basic® .NET) if the recognizer cannot compute a result for the Strokes collection.

Note: You must use a try/catch block when calling the Recognize method because an exception is thrown when the Ink object contains no strokes.

This method performs recognition synchronously. To start background, or asynchronous recognition, call the BackgroundRecognize or BackgroundRecognizeWithAlternates methods.

Examples

[C#]

This C# example shows an event handler for a Button Leave Site control's Click Leave Site event, buttonSubmit_Click, that recognizes the ink in its RecognizerContext object, theRecognizerContext, declared in a containing scope. The example then displays the RecognitionResult object, theRecognitionResult in a TextBox Leave Site control if no errors occurred.

private void buttonSubmit_Click(object sender, System.EventArgs e)
{
    RecognitionStatus theRecognitionStatus;
    theRecognizerContext.EndInkInput();
    try
    {
      theRecognitionResult = theRecognizerContext.Recognize(out theRecognitionStatus);
      if (RecognitionStatus.NoError == theRecognitionStatus)
      {
        theTextBox.Text = theRecognitionResult.TopString;
      }
      else
      {
         theTextBox.Text = "";
      }
    }
    catch
    {
      // If Ink object in theRecognizerContext contains no strokes or only
      // deleted strokes, exception is thrown.
      theTextBox.Text = "";
    }
}

[Visual Basic .NET]

This C# example shows an event handler for a Button Leave Site control's Click Leave Site event, buttonSubmit_Click, that recognizes the ink in its RecognizerContext object, theRecognizerContext, declared in a containing scope. The example then displays the RecognitionResult object, theRecognitionResult in a TextBox Leave Site control if no errors occurred.

Private Sub Button1_Click( ByVal sender As System.Object, _
  ByVal e As System.EventArgs) Handles Button1.Click
    theRecognizerContext.EndInkInput()
    Dim theRecognitionStatus As RecognitionStatus
    Try
        theRecognitionResult = theRecognizerContext.Recognize(theRecognitionStatus)
        If RecognitionStatus.NoError = theRecognitionStatus Then
            RichTextBox1.Text = theRecognitionResult.TopString
        Else
            'Handle the error conditions here.
            RichTextBox1.Text = ""
        End If
    Catch
        ' If Ink object in theRecognizerContext contains no strokes or only
        ' deleted strokes, exception is thrown.
        RichTextBox1.Text = ""
    End Try
End Sub

See Also