Using the Tablet PC SDK in Visual Studio .NET Using C# v0.2a, JL Popyack, Feb. 2004 (Revised July 2004)

Using the Tablet PC Software Development Kit (SDK)

Update your .NET settings to include the Tablet PC SDK: Select Project -> Add Reference… and click the “.NET” tab. Scroll down to find Microsoft Tablet PC API v1.5 and select that, click the Select button, then click “the OK”.button.

Make sure the Toolbox is visible. If it is not, select the “Toolbox” tab in the left margin of the Visual Studio. Right-click in the Toolbox window, and select Customize Toolbox… (In Visual Studio .NET 2003, select Add/Remove Items…) Find and select the InkEdit and InkPicture components by clicking the checkboxes beside these items. This allows Ink icons to appear in the Toolbox, for easy installation in your project.

Prepared for "Developing Software for the Tablet PC", JL Popyack, B Char, N Herrmann: Project DUPLEX, Drexel University, SIGCSE Technical Symposium, Mar.3, 2004. Revised for use by PGSIT, 2004. Prepared for "Developing Software for the Tablet PC", JL Popyack, B Char, N Herrmann: Project DUPLEX, Drexel University, SIGCSE Technical Symposium, Mar.3, 2004. Revised for use by PGSIT, 2004. To place an InkEdit object in your form, click on InkEdit, and drag it into place on the form, where it can be repositioned and resized.

Prepared for "Developing Software for the Tablet PC", JL Popyack, B Char, N Herrmann: Project DUPLEX, Drexel University, SIGCSE Technical Symposium, Mar.3, 2004. Revised for use by PGSIT, 2004. Switch to Code View. At the top, add a line containing “using Microsoft.Ink;”

Prepared for "Developing Software for the Tablet PC", JL Popyack, B Char, N Herrmann: Project DUPLEX, Drexel University, SIGCSE Technical Symposium, Mar.3, 2004. Revised for use by PGSIT, 2004. In the Solution Explorer window, select the Form1.cs icon, and select View->Properties Window (alternately, double-click the Form1.cs icon). You can modify the properties of Form1.cs. Change the default value of Text from “inkEdit1” to the null string.

Prepared for "Developing Software for the Tablet PC", JL Popyack, B Char, N Herrmann: Project DUPLEX, Drexel University, SIGCSE Technical Symposium, Mar.3, 2004. Revised for use by PGSIT, 2004. Ink recognition is automatically turned on. Try running the program (select Build->Build Solution to build it, and Debug->Run without Debugging to run it.)

The display font, size, style and color can be changed from the Properties menu. Click on the Ink Edit item, and click the “+” next to Font from the Properties menu. Various attributes such as Font, Size, and Color can be changed here. Below, we have set Font to Jokerman, Color to Red, and Size to 16:

Prepared for "Developing Software for the Tablet PC", JL Popyack, B Char, N Herrmann: Project DUPLEX, Drexel University, SIGCSE Technical Symposium, Mar.3, 2004. Revised for use by PGSIT, 2004.

Let’s create an application that will accept numbers as user input and total them. The form will look like this:

Create this by placing InkEdit boxes for Score1, Score2, and Total. Modify the inputs through the Properties menu: Change the text for label1 to “Score 1”by selecting its Text property, and likewise for the other labels. Modify the display text for InkEdit1: change the text to null, font to 14 point, and likewise for InkEdit2 and InkEdit3. Ensure the boxes are the same size and are aligned vertically by modifying their Size and Location properties. (Each of these properties has two components; access them individually by clicking the “+” box next to the property name.) Prepared for "Developing Software for the Tablet PC", JL Popyack, B Char, N Herrmann: Project DUPLEX, Drexel University, SIGCSE Technical Symposium, Mar.3, 2004. Revised for use by PGSIT, 2004. Modify the title bar of the form by clicking it and changing its Text property.

Test run the application. Each box has recognition turned on automatically. Try writing in numbers. How good is the recognition? We note it is not perfect.

An InkEdit object allows factoids (i.e., hints) as to the type of its input. Initially, the factoid for InkEdit objects is DEFAULT. Some other possibilities are shown below:

ONECHAR...... a single character UPPERCHAR...... single upper case character DIGIT...... a single digit DATE...... standard format dates TIME...... stardard form time CURRENCY...... various forms (including dollars, cents, pounds, euros, …) TELEPHONE...... phone number EMAIL...... standard-form email address WEB...... URL FILENAME...... file path format WORDLIST...... you can specify a set of likely words NONE...... you’re on your own!

Specify the factoid to be used by an InkEdit object through its Factoid property. Can’t decide between DIGIT and NUMBER? Change the factoids for InkEdit1 to NUMBER and InkEdit2 to DIGIT and try both. Prepared for "Developing Software for the Tablet PC", JL Popyack, B Char, N Herrmann: Project DUPLEX, Drexel University, SIGCSE Technical Symposium, Mar.3, 2004. Revised for use by PGSIT, 2004. Note: you can also “OR” several factoids: EMAIL | WEB, for instance.

For more robust development, the InkEdit type lacks some features, e.g., the ability to control what is collected. Whereas factoid hints are accepted, they are no guarantee that the text returned will conform to the factoid.

Open the InkRecognition C# Project. Find the source code (in btnRecognize_Click) shown below. Follow the instructions (uncomment the code) and also comment out the last line (which calls the ToString() method.

// Note that the Strokes' ToString() method is a // shortcut for retrieving the best match using the // default recognizer. The same result can also be // obtained using the RecognizerContext. For an // example, uncomment the following lines of code: // // using (RecognizerContext myRecoContext = new RecognizerContext()) // { // RecognitionStatus status; // RecognitionResult recoResult; // // myRecoContext.Strokes = myInkCollector.Ink.Strokes; // recoResult = myRecoContext.Recognize(out status); // txtResults.SelectedText = recoResult.TopString; // } txtResults.SelectedText = myInkCollector.Ink.Strokes.ToString();

Run the program to verify that it still works.

Next, add the following lines of code, before the line that says “myRecoContext.Strokes = myInkCollector.Ink.Strokes;”

myRecoContext.Factoid = "NUMBER" ; myRecoContext.RecognitionFlags = RecognitionModes.Coerce;

The first line supplies the factoid that says the Ink collected should be a number. The second line forces this to happen – the result returned will be a number.

Perhaps you would like to restrict Tablet input to a specific list of words. You can do this with the following code:

Microsoft.Ink.WordList myWordList = new WordList(); myWordList.Add("true"); myWordList.Add("false");

myRecoContext.WordList = myWordList;

Prepared for "Developing Software for the Tablet PC", JL Popyack, B Char, N Herrmann: Project DUPLEX, Drexel University, SIGCSE Technical Symposium, Mar.3, 2004. Revised for use by PGSIT, 2004. myRecoContext.Factoid = Factoid.WordList; myRecoContext.RecognitionFlags = RecognitionModes.Coerce ;

The first few lines create a wordlist and assign it to the Recognition context. The next line makes this a factoid (this is an alternate form of the similar line used for the NUMBER factoid) and the last line coerces the input to be one of the words on the list.

Modify the word list as you desire!

Prepared for "Developing Software for the Tablet PC", JL Popyack, B Char, N Herrmann: Project DUPLEX, Drexel University, SIGCSE Technical Symposium, Mar.3, 2004. Revised for use by PGSIT, 2004.