RecognizerContextRecognitionWithAlternatesEventArgs.CustomData Property

RecognizerContextRecognitionWithAlternatesEventArgs.CustomData Property

Gets the object that contains the custom data for the recognition result.

Definition

Visual Basic .NET Public ReadOnly Property CustomData As Object
C# public object CustomData { get; }
Managed C++ public: __property Object* get_CustomData();

Property Value

System.Object. The custom data for the recognition result.

This property is read-only. This property has no default value.

Remarks

You can supply custom data when you call the BackgroundRecognizeWithAlternates method of the RecognizerContext object. When the RecognizerContext object raises the RecognitionWithAlternates event, the custom data will be available in the CustomData property of the RecognizerContextRecognitionWithAlternatesEventArgs object.

Examples

[C#]

This C# example is from a Form Leave Site, RecognitionWithAlternatesEventForm, that performs background recognition with alternates by calling the BackgroundRecognizeWithAlternates method of the RecognizerContext object, theRecognizerContext, as each stroke is collected and displays the result along with all of its alternates in descending order of confidence in the ListBox Leave Site control, listAlternates, as they are generated.

A time stamp is used in the call to the BackgroundRecognizeWithAlternates method. The event handler for the RecognitionWithAlternates event, RecognitionWithAlternates_Event, retrieves the time stamp by checking the CustomData property of the event arguments.

private Microsoft.Ink.InkCollector theInkCollector;
private Microsoft.Ink.Strokes theStrokes;
private Microsoft.Ink.RecognizerContext theRecognizerContext;
private Microsoft.Ink.RecognitionResult theRecognitionResult;

private System.Windows.Forms.ListBox listAlternates;

// Event handler for the form's Load event
private void RecognitionWithAlternatesEventForm_Load(object sender, System.EventArgs e)
{
    // Create a new ink collector and recognizer context.
    this.theInkCollector = new Microsoft.Ink.InkCollector(this.Handle);
    this.theRecognizerContext = new Microsoft.Ink.RecognizerContext();

    // Initialize the RecognizerContext object's strokes.
    this.theStrokes = this.theInkCollector.Ink.Strokes;
    this.theRecognizerContext.Strokes = this.theStrokes;

    // Attach event handlers.
    this.theInkCollector.Stroke +=
        new InkCollectorStrokeEventHandler(this.Stroke_Event);
    this.theRecognizerContext.RecognitionWithAlternates +=
        new RecognizerContextRecognitionWithAlternatesEventHandler(
        this.RecognitionWithAlternates_Event);

    // Enable the ink collector
    this.theInkCollector.Enabled = true;
}

// Stroke event handler
private void Stroke_Event(object sender,
    InkCollectorStrokeEventArgs e)
{
    // When a new stroke is collected,
    // add it to the recognizer's strokes collection.
    this.theStrokes.Add(e.Stroke);

    // Tell the context to recognize its strokes.
    // Add a time stamp as custom data for the RecognitionWithAlternates event.
    DateTime timeStamp = DateTime.Now;
    this.theRecognizerContext.BackgroundRecognizeWithAlternates(timeStamp);
}

// Recognition Event Handler
private void RecognitionWithAlternates_Event(
    object sender,
    RecognizerContextRecognitionWithAlternatesEventArgs e)
{
    this.theRecognitionResult = e.Result;
    Microsoft.Ink.RecognitionAlternates theRecognitionAlternates =
        this.theRecognitionResult.GetAlternatesFromSelection(0, -1);

    // Update the Text box
    this.listAlternates.Items.Clear();
    this.listAlternates.Items.Add("The recognition status is: " + e.RecognitionStatus.ToString());
    this.listAlternates.Items.Add("The time stamp is: " + ((DateTime)e.CustomData).ToString());
    foreach (Microsoft.Ink.RecognitionAlternate theRecognitionAlternate in theRecognitionAlternates)
    {
        this.listAlternates.Items.Add(theRecognitionAlternate.ToString());
    }
}

// Event handler for the form's closed event
private void RecognitionWithAlternatesEventForm_Closed(object sender, System.EventArgs e)
{
    this.theInkCollector.Dispose();
    this.theInkCollector = null;
    this.theRecognizerContext.Dispose();
    this.theRecognizerContext = null;
}

[Visual Basic .NET]

This Microsoft® Visual Basic® .NET example is from a Form Leave Site, RecognitionWithAlternatesEventForm, that performs background recognition with alternates by calling the BackgroundRecognizeWithAlternates method of the RecognizerContext object, theRecognizerContext, as each stroke is collected and displays the result along with all of its alternates in descending order of confidence in the ListBox Leave Site control, listAlternates, as they are generated.

A time stamp is used in the call to the BackgroundRecognizeWithAlternates method. The event handler for the RecognitionWithAlternates event, RecognitionWithAlternates_Event, retrieves the time stamp by checking the CustomData property of the event arguments.

Private WithEvents theInkCollector As Microsoft.Ink.InkCollector
Private WithEvents theRecognizerContext As Microsoft.Ink.RecognizerContext
Private theStrokes As Microsoft.Ink.Strokes
Private theRecognitionResult As Microsoft.Ink.RecognitionResult

' Event handler for the form's Load event.
Private Sub RecognitionWithAlternatesEventForm_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load
    ' Create a new ink collector and recognizer context.
    Me.theInkCollector = New Microsoft.Ink.InkCollector(Me.Handle)
    Me.theRecognizerContext = New Microsoft.Ink.RecognizerContext

    ' Initialize the RecognizerContext object's strokes
    Me.theStrokes = Me.theInkCollector.Ink.Strokes
    Me.theRecognizerContext.Strokes = Me.theStrokes

    ' Enable the ink collector
    Me.theInkCollector.Enabled = True
End Sub

' Stroke event handler.
Private Sub Stroke_Event(ByVal sender As Object, _
    ByVal e As Microsoft.Ink.InkCollectorStrokeEventArgs) Handles theInkCollector.Stroke

    ' When a new stroke is collected,
    ' add it to the recognizer's strokes collection.
    Me.theStrokes.Add(e.Stroke)

    ' Tell the context to recognize its strokes.
    ' Add a time stamp as custom data for the RecognitionWithAlternates event.
    Dim timeStamp As System.DateTime = DateTime.Now
    Me.theRecognizerContext.BackgroundRecognizeWithAlternates(timeStamp)
End Sub

' Recognition Event Handler.
Private Sub RecognitionWithAlternates_Event(ByVal sender As Object, _
    ByVal e As Microsoft.Ink.RecognizerContextRecognitionWithAlternatesEventArgs) _
    Handles theRecognizerContext.RecognitionWithAlternates

    Me.theRecognitionResult = e.Result
    Dim theRecognitionAlternates As Microsoft.Ink.RecognitionAlternates = _
        Me.theRecognitionResult.GetAlternatesFromSelection(0, -1)

    ' Update the Text box
    Me.listAlternates.Items.Clear()
    Me.listAlternates.Items.Add("The recognition status is: " & _
        e.RecognitionStatus.ToString())
    Me.listAlternates.Items.Add("The time stamp is: " & _
        DirectCast(e.CustomData, System.DateTime).ToString())

    For Each theRecognitionAlternate As Microsoft.Ink.RecognitionAlternate In theRecognitionAlternates
        Me.listAlternates.Items.Add(theRecognitionAlternate.ToString())
    Next
End Sub

' Event handler for the form's closed event.
Private Sub RecognitionWithAlternatesEventForm_Closed(ByVal sender As Object, _
    ByVal e As System.EventArgs) Handles MyBase.Closed
    Me.theInkCollector.Dispose()
    Me.theInkCollector = Nothing
    Me.theRecognizerContext.Dispose()
    Me.theRecognizerContext = Nothing
End Sub

See Also