다음을 통해 공유


RecognizerContext.Recognition 이벤트

업데이트: 2007년 11월

RecognizerContext 개체가 BackgroundRecognize 메서드에서 결과를 생성한 경우 발생합니다.

네임스페이스:  Microsoft.Ink
어셈블리:  Microsoft.Ink(Microsoft.Ink.dll)

구문

‘선언
Public Event Recognition As RecognizerContextRecognitionEventHandler
‘사용 방법
Dim instance As RecognizerContext
Dim handler As RecognizerContextRecognitionEventHandler

AddHandler instance.Recognition, handler
public event RecognizerContextRecognitionEventHandler Recognition
public:
 event RecognizerContextRecognitionEventHandler^ Recognition {
    void add (RecognizerContextRecognitionEventHandler^ value);
    void remove (RecognizerContextRecognitionEventHandler^ value);
}
/** @event */
public void add_Recognition (RecognizerContextRecognitionEventHandler value)
/** @event */
public void remove_Recognition (RecognizerContextRecognitionEventHandler value)
JScript에서는 이벤트를 지원하지 않습니다.

설명

이벤트 처리기는 이 이벤트에 대한 데이터가 들어 있는 RecognizerContextRecognitionEventArgs 형식의 인수를 받습니다.

RecognizerContextRecognitionEventHandler 대리자를 만드는 경우 이벤트를 처리하는 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다.

인식 이벤트 처리기에서 원래 RecognizerContext 개체에 액세스하려고 하면 API(응용 프로그래밍 인터페이스)에서 예기치 않은 동작이 발생할 수 있습니다. 이러한 작업을 수행하면 안 됩니다. 이러한 작업이 필요한 경우에는 대신 플래그를 만들어 Recognition 이벤트 처리기에서 설정하십시오. 그러면 해당 플래그를 폴링하여 이벤트 처리기 외부에서 RecognizerContext 속성을 변경할 시기를 결정할 수 있습니다.

예제

이 예제에서는 InkOverlay 개체에 작성되는 각 스트로크를 자동으로 인식하고 인식 결과를 표시합니다.

응용 프로그램 시작 중에 RecognizerContext 개체가 인스턴스화되고 이벤트 처리기가 할당됩니다.

' create a new RecognizerContext object
' the object's Strokes property is initialized to null
mRecognizerContext = New RecognizerContext()
' assign the Strokes property by creating a fresh Strokes collection 
mRecognizerContext.Strokes = mInkOverlay.Ink.CreateStrokes()
' subscribe to the Strokes event. It is during this event
' that we can add strokes to the RecognizerContext
AddHandler mInkOverlay.Stroke, New InkCollectorStrokeEventHandler(AddressOf mInkOverlay_Stroke2)
' subscribe to the the Recognition event. 
' This event is fired when background recognition is complete, 
' and recognition results (without alternates) are available
AddHandler mRecognizerContext.Recognition, _
        New RecognizerContextRecognitionEventHandler(AddressOf mRecognizerContext_Recognition)
// create a new RecognizerContext object
// the object's Strokes property is initialized to null
mRecognizerContext = new RecognizerContext();
// assign the Strokes property by creating a fresh Strokes collection 
mRecognizerContext.Strokes = mInkOverlay.Ink.CreateStrokes();
// subscribe to the Strokes event. It is during this event
// that we can add strokes to the RecognizerContext
mInkOverlay.Stroke += new InkCollectorStrokeEventHandler(mInkOverlay_Stroke2);
// subscribe to the the Recognition event. 
// This event is fired when background recognition is complete, 
// and recognition results (without alternates) are available
mRecognizerContext.Recognition += 
    new RecognizerContextRecognitionEventHandler(mRecognizerContext_Recognition);

사용자가 스트로크를 완성하여 Stroke 이벤트가 발생하면 새로 만들어진 스트로크가 RecognizerContext 개체의 Strokes 컬렉션에 추가되고 BackgroundRecognize 메서드가 호출됩니다.

Private Sub mInkOverlay_Stroke2(ByVal sender As Object, ByVal e As InkCollectorStrokeEventArgs)
    ' in case background recognition is still occurring, stop it
    mRecognizerContext.StopBackgroundRecognition()
    ' add the stroke, and start recognition
    mRecognizerContext.Strokes.Add(e.Stroke)
    mRecognizerContext.BackgroundRecognize()
End Sub
private void mInkOverlay_Stroke2(object sender, InkCollectorStrokeEventArgs e)
{
    // in case background recognition is still occurring, stop it
    mRecognizerContext.StopBackgroundRecognition();
    // add the stroke, and start recognition
    mRecognizerContext.Strokes.Add(e.Stroke);
    mRecognizerContext.BackgroundRecognize();
}

백그라운드 인식이 완료되면 Recognition 이벤트가 발생합니다. 이 이벤트를 처리하는 동안 인식 결과가 목록 상자에 배치됩니다.

' event fires when recognition results (without alternates) are ready
Private Sub mRecognizerContext_Recognition(ByVal sender As Object, _
            ByVal e As RecognizerContextRecognitionEventArgs)
    ' when updating a control, must use Invoke() since controls are
    ' not thread safe and recognition occurs on a different thread
    If Me.InvokeRequired Then
        ' recursively call this method via Invoke()
        Me.Invoke( _
            New RecognizerContextRecognitionEventHandler(AddressOf mRecognizerContext_Recognition), _
            New Object() {sender, e} _
        )
        Return
    End If
    If RecognitionStatus.NoError = e.RecognitionStatus Then
        listBoxRecognitionResults.Items.Add(e.Text)
    End If
End Sub
// event fires when recognition results (without alternates) are ready
private void mRecognizerContext_Recognition(object sender, RecognizerContextRecognitionEventArgs e)
{
    // when updating a control, must use Invoke() since controls are
    // not thread safe and recognition occurs on a different thread
    if (this.InvokeRequired)
    {
        // recursively call this method via Invoke()
        this.Invoke(
            new RecognizerContextRecognitionEventHandler(mRecognizerContext_Recognition), 
            new object[] { sender, e }
            );
        return;
    }
    if (RecognitionStatus.NoError == e.RecognitionStatus)
    {
        listBoxRecognitionResults.Items.Add(e.Text);
    }
}

플랫폼

Windows Vista

.NET Framework 및 .NET Compact Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.

버전 정보

.NET Framework

3.0에서 지원

참고 항목

참조

RecognizerContext 클래스

RecognizerContext 멤버

Microsoft.Ink 네임스페이스

RecognitionResult

RecognitionStatus

RecognizerContext.BackgroundRecognize

RecognizerContext.Recognize