RecognizerContextRecognitionWithAlternatesEventHandler 대리자
업데이트: 2007년 11월
RecognizerContext 개체의 RecognitionWithAlternates 이벤트를 처리하는 메서드를 나타냅니다.
네임스페이스: Microsoft.Ink
어셈블리: Microsoft.Ink(Microsoft.Ink.dll)
구문
‘선언
Public Delegate Sub RecognizerContextRecognitionWithAlternatesEventHandler ( _
sender As Object, _
e As RecognizerContextRecognitionWithAlternatesEventArgs _
)
‘사용 방법
Dim instance As New RecognizerContextRecognitionWithAlternatesEventHandler(AddressOf HandlerMethod)
public delegate void RecognizerContextRecognitionWithAlternatesEventHandler(
Object sender,
RecognizerContextRecognitionWithAlternatesEventArgs e
)
public delegate void RecognizerContextRecognitionWithAlternatesEventHandler(
Object^ sender,
RecognizerContextRecognitionWithAlternatesEventArgs^ e
)
/** @delegate */
public delegate void RecognizerContextRecognitionWithAlternatesEventHandler(
Object sender,
RecognizerContextRecognitionWithAlternatesEventArgs e
)
JScript에서는 대리자를 지원하지 않습니다.
매개 변수
- sender
형식: System.Object
이 이벤트의 소스 RecognizerContext 개체입니다.
- e
형식: Microsoft.Ink.RecognizerContextRecognitionWithAlternatesEventArgs
이벤트 데이터가 들어 있는 RecognizerContextRecognitionWithAlternatesEventArgs 개체입니다.
설명
RecognitionWithAlternates 이벤트는 BackgroundRecognizeWithAlternates 메서드를 호출한 후 RecognizerContext에서 결과가 생성될 때 발생합니다.
RecognizerContextRecognitionWithAlternatesEventHandler 대리자를 만드는 경우 이벤트를 처리하는 메서드를 식별합니다. 이벤트를 이벤트 처리기와 연결하려면 대리자의 인스턴스를 해당 이벤트에 추가합니다. 대리자를 제거하지 않는 경우 이벤트가 발생할 때마다 이벤트 처리기가 호출됩니다.
참고
RecognizerContextRecognitionEventHandler 대리자에서 원래 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_Stroke1)
' subscribe to the the RecognitionWithAlternates event.
' This event is fired when background recognition is complete,
' and recognition results (with alternates) are available
AddHandler mRecognizerContext.RecognitionWithAlternates, _
New RecognizerContextRecognitionWithAlternatesEventHandler(AddressOf mRecognizerContext_RecognitionWithAlternates)
// 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_Stroke1);
// subscribe to the the RecognitionWithAlternates event.
// This event is fired when background recognition is complete,
// and recognition results (with alternates) are available
mRecognizerContext.RecognitionWithAlternates +=
new RecognizerContextRecognitionWithAlternatesEventHandler(mRecognizerContext_RecognitionWithAlternates);
사용자가 스트로크를 완성하여 Stroke 이벤트가 발생하면 새로 만들어진 스트로크가 RecognizerContext 개체의 Strokes 컬렉션에 추가되고 BackgroundRecognizeWithAlternates 메서드가 호출됩니다.
Private Sub mInkOverlay_Stroke1(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.BackgroundRecognizeWithAlternates()
End Sub
private void mInkOverlay_Stroke1(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.BackgroundRecognizeWithAlternates();
}
백그라운드 인식이 완료되면 RecognitionWithAlternates 이벤트가 발생합니다. 이 이벤트를 처리하는 동안 대체 항목을 포함한 인식 결과가 목록 상자에 배치됩니다.
' event fires when recognition results (with alternates) are ready
Private Sub mRecognizerContext_RecognitionWithAlternates(ByVal sender As Object, _
ByVal e As RecognizerContextRecognitionWithAlternatesEventArgs)
' 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 RecognizerContextRecognitionWithAlternatesEventHandler(AddressOf mRecognizerContext_RecognitionWithAlternates), _
New Object() {sender, e} _
)
Return
End If
If RecognitionStatus.NoError = e.RecognitionStatus Then
' show the top alternate
listBoxRecognitionResults.Items.Add("TOP:" + e.Result.TopAlternate.ToString())
' get the rest of the alternates
Dim allAlternates As RecognitionAlternates = e.Result.GetAlternatesFromSelection()
' show each of the other alternates
For Each oneAlternate As RecognitionAlternate In allAlternates
listBoxRecognitionResults.Items.Add("ALT:" + oneAlternate.ToString())
Next
End If
End Sub
// event fires when recognition results (with alternates) are ready
private void mRecognizerContext_RecognitionWithAlternates(object sender, RecognizerContextRecognitionWithAlternatesEventArgs 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 RecognizerContextRecognitionWithAlternatesEventHandler(mRecognizerContext_RecognitionWithAlternates),
new object[] { sender, e }
);
return;
}
if (RecognitionStatus.NoError == e.RecognitionStatus)
{
// show the top alternate
listBoxRecognitionResults.Items.Add("TOP:" + e.Result.TopAlternate.ToString());
// get the rest of the alternates
RecognitionAlternates allAlternates = e.Result.GetAlternatesFromSelection();
// show each of the other alternates
foreach (RecognitionAlternate oneAlternate in allAlternates)
{
listBoxRecognitionResults.Items.Add("ALT:" + oneAlternate.ToString());
}
}
}
플랫폼
Windows Vista
.NET Framework 및 .NET Compact Framework에서 모든 플랫폼의 전체 버전을 지원하지는 않습니다. 지원되는 버전의 목록을 보려면 .NET Framework 시스템 요구 사항을 참조하십시오.
버전 정보
.NET Framework
3.0에서 지원