Share via


RecognizerContext.Recognize Method

Returns a RecognitionResult object for a Strokes collection.

Namespace:  Microsoft.Ink
Assembly:  Microsoft.Ink (in Microsoft.Ink.dll)

Syntax

'Declaration
Public Function Recognize ( _
    <OutAttribute> ByRef recognitionStatus As RecognitionStatus _
) As RecognitionResult
'Usage
Dim instance As RecognizerContext 
Dim recognitionStatus As RecognitionStatus 
Dim returnValue As RecognitionResult 

returnValue = instance.Recognize(recognitionStatus)
public RecognitionResult Recognize(
    out RecognitionStatus recognitionStatus
)
public:
RecognitionResult^ Recognize(
    [OutAttribute] RecognitionStatus% recognitionStatus
)
public function Recognize(
    recognitionStatus : RecognitionStatus
) : RecognitionResult

Parameters

Return Value

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

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

This C# example shows an event handler for a Button control's Click 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 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 = "";
    }
}

This Microsoft® Visual Basic® .NET example shows an event handler for a Button control's Click 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 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

Platforms

Windows 7, Windows Vista, Windows Server 2008 R2, Windows Server 2008

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Version Information

.NET Framework

Supported in: 3.0

See Also

Reference

RecognizerContext Class

RecognizerContext Members

Microsoft.Ink Namespace

RecognizerContext.BackgroundRecognize

RecognizerContext.BackgroundRecognizeWithAlternates

Ink

Strokes

RecognitionResult.Strokes