이 애플리케이션은 필기 인식 애플리케이션을 빌드하는 방법을 보여 줍니다. Windows Vista SDK는 C# 및 Visual Basic .NET에서도 이 샘플의 버전을 제공합니다. 이 항목에서는 Visual Basic .NET 샘플을 참조하지만 개념은 버전 간에 동일합니다.
태블릿 PC 인터페이스 액세스
먼저 SDK와 함께 설치된 태블릿 PC API를 참조합니다.
' The Ink namespace, which contains the Tablet PC Platform API
Imports Microsoft.Ink
InkCollector 초기화
샘플은 InkCollector, myInkCollector를 그룹 상자 창과 연결하고 InkCollector를 사용하도록 설정하는 역할을 하는 양식의 Load 이벤트 처리기에 코드를 추가합니다.
Private Sub InkRecognition_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
' Create the recognizers collection
myRecognizers = New Recognizers()
' Create an ink collector that uses the group box handle
myInkCollector = New InkCollector(gbInkArea.Handle)
' Turn the ink collector on
myInkCollector.Enabled = True
End Sub
스트로크 인식
Button 개체의 Click 이벤트 처리기는 Recognizeers 컬렉션의 Count 속성을 검사하여 사용자에게 하나 이상의 인식기가 설치되어 있는지 확인합니다.
텍스트 상자의 SelectedText 속성은 Strokes 컬렉션의 ToString 메서드를 사용하여 스트로크에 가장 적합한 값으로 설정됩니다. 스트로크가 인식되면 삭제됩니다. 마지막으로 코드는 그리기 영역을 강제로 다시 칠하여 추가 잉크 사용을 위해 지웁니다.
Private Sub btnRecognize_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecognize.Click
' Check to ensure that the user has at least one recognizer installed
' Note that this is a preventive check - otherwise, an exception
' occurs during recognition
If 0 = myRecognizers.Count Then
MessageBox.Show("There are no handwriting recognizers installed. You need to have at least one in order to run this sample.")
Else
' ...
txtResults.SelectedText = myInkCollector.Ink.Strokes.ToString
' If the mouse is pressed, do not perform the recognition -
' this prevents deleting a stroke that is still being drawn
If Not myInkCollector.CollectingInk Then
' Delete the ink from the ink collector
myInkCollector.Ink.DeleteStrokes(myInkCollector.Ink.Strokes)
' Force the Frame to redraw (so the deleted ink goes away)
gbInkArea.Refresh()
End If
End If
End Sub
양식 닫기
폼의 Dispose 메서드는 InkCollector 개체를 삭제합니다.