Compartir a través de


RecognizerContextRecognitionEventArgs.CustomData Property

RecognizerContextRecognitionEventArgs.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 object that contains 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 is available in the CustomData property of the RecognizerContextRecognitionWithAlternatesEventArgs object.

Examples

[C#]

This C# example is from a Form Leave Site, RecognitionEventForm, that performs background recognition by calling the BackgroundRecognize method of the RecognizerContext object, theRecognizerContext, as each stroke is collected and displays the result in the ListBox Leave Site control, theListBox, as they are generated.

A time stamp is used in the call to the BackgroundRecognize method. The event handler for the Recognition event, Recognition_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 System.Windows.Forms.ListBox theListBox;

// Event handler for the form's Load event
private void RecognitionEventForm_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.Recognition +=
        new RecognizerContextRecognitionEventHandler(
            this.Recognition_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 Recognition event.
    DateTime timeStamp = DateTime.Now;
    this.theRecognizerContext.BackgroundRecognize(timeStamp);
}

// Recognition Event Handler
private void Recognition_Event(
    object sender,
    RecognizerContextRecognitionEventArgs e)
{
    // Update the list box
    this.theListBox.Items.Clear();
    this.theListBox.Items.Add("The recognition status is: " + e.RecognitionStatus.ToString());
    this.theListBox.Items.Add("The time stamp is: " + ((DateTime)e.CustomData).ToString());
    this.theListBox.Items.Add("The recogniton text is: " + e.Text);
}

// Event handler for the form's closed event
private void RecognitionEventForm_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, RecognitionEventForm, that performs background recognition by calling the BackgroundRecognize method of the RecognizerContext object, theRecognizerContext, as each stroke is collected and displays the result in the ListBox Leave Site control, theListBox, as they are generated.

A time stamp is used in the call to the BackgroundRecognize method. The event handler for the Recognition event, Recognition_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

' Event handler for the form's Load event.
Private Sub RecognitionEventForm_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.BackgroundRecognize(timeStamp)
End Sub

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

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

' Event handler for the form's closed event.
Private Sub RecognitionEventForm_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