ENEE408G Multimedia Signal Processing Pen Computing and Tablet PC Programming Manual

ENEE408G Multimedia Signal Processing Pen Computing and Tablet PC Programming Manual Using Microsoft Visual Studio.NET C# and Tablet PC Platform SDK ...
Author: Dustin Skinner
22 downloads 2 Views 1MB Size
ENEE408G Multimedia Signal Processing Pen Computing and Tablet PC Programming Manual Using Microsoft Visual Studio.NET C# and Tablet PC Platform SDK

Guan-Ming Su Min Wu K. J. Ray Liu

Department of Electrical and Computer Engineering University of Maryland at College park Last Updated: October 7, 2003

Contents

Part I. Tablet PC and Tablet PC Platform SDK 1. Tablet PC 2. Tablet PC Platform SDK 3. Tablet Managed API

Part II. Microsoft Visual Studio .NET 1. Introduction to .NET Framework 2. Visual Studio .Net Integrated Design Environment (IDE) 3. Using Tablet PC API in Visual Studio .NET

Part III. Ink Collection and Display – Pen API 1. InkCollector 2. InkOverlay

2 2 3 4

6 6 6 7

10 10 12

Part IV. Ink Data Management– Ink API

17

1. Overview 2. Example: PacketStrokeViewer 3. Ink Serialization

17 18 24

Part V. Ink Recognition – Recognition API 1. Ink Recognition using Strokes.ToString 2.Using the Recognizers Classes

Part VI. Ink Controls 1. InkEdit 2. InkPicture

Part VII. Further References

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

31 31 35

38 38 43

49

1

Part I. Tablet PC and Tablet PC Platform SDK 1. Tablet PC1 (a) Hardware Tablet PC is a fully capable PC you can interact with in new and different ways. With its tablet pen and ink technology, your Tablet PC is a writing pad that lets you handwrite text and drawings into the computer. And with its speech recognition capabilities, your Tablet PC is a dictation machine that converts your voice into text. You can also use the pen and your voice to control your computer—or if you prefer, you can control your Tablet PC with a standard keyboard and mouse. The following figures show an example of Tablet PC.

Figure I-1

(b) Features • • •

• •



1

Write the Way You Want – The Tablet PC enables you to write and store information in your own handwriting and easily converts your notes into typed text for use in other Windows XP–compatible applications. Enter Text in Multiple Ways - You can input text using the tablet pen, your voice, an on-screen keyboard, or a standard keyboard. Be More Productive with Tablet PC Tools: 1. Microsoft Windows Journal. A note-taking accessory. 2. Input Panel. A tablet pen and voice input accessory. 3. Sticky Notes. An electronic version of the paper-based original. Mark Up Documents with Your Handwritten Comments - You can annotate/mark up the viewed documents from other applications (such as web pages) with your handwritten comments and forward them to your friends. Enjoy a Natural and Comfortable Way to Read- Designed to give you a natural and comfortable reading experience, Tablet PC uses a high-resolution display and Microsoft ClearType®, a technology that makes reading on your computer easier and less tiring. Rotate Your Screen to Accommodate Your Work- Tablet PC allows you to quickly and easily switch your screen orientation from portrait to landscape. You can choose portrait orientation when you take handwritten notes in a meeting. If working on a Microsoft PowerPoint presentation, you can choose landscape. Switch screen orientation as often as you need for your changing work environments and scenarios. Adopted from http://www.microsoft.com/windowsxp/tabletpc/evaluation/overviews/usepc.asp

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

2

2. Tablet PC Platform SDK2 The Tablet PC platform SDK can be divided into three distinct areas: • Ink collection (objects that are used to collect ink from the digitizer). • Ink data management (objects that are used to manage the collected ink). • Ink recognition (objects that are used to convert the collected ink into other types of data, such as text). The following image3 shows, at a high level, how the Ink Collection API (Pen API), Ink Data Management API (Ink API), and Ink Recognition API (Recognition API) work together in the Tablet PC platform.

Figure I-2

We show the Tablet PC Platform SDK architecture in the below figure. Tablet PC Platform SDK Ink Controls InkEdit

InkPicture

Managed APIs Tablet input; Ink Collection (Pen API) Ink Data Management (Ink API) Ink Recognition (Recognition API)

COM automation APIs

Win32 APIs .NET Framework

GDI+

RichEdit

Other Win32 Services

Figure I-3 2

Tablet PC Platform SDK can be downloaded at http://msdn.microsoft.com/library/default.asp?url=/downloads/list/windevtpc.asp 3 Adopted from: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/tpcsdk10/html/managed/ tbidxautoomdiagram.asp ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

3

3. Tablet Managed API4 Figure I-4 shows the objects belonging to Pen API, Ink API, and Recognition API in the Tablet Managed API. Tablet Input API (Pen API) Cursor CursorButton Cursors Gesture InkCollector InkOverlay Tablets Tablet

Ink Data Management (Ink API)

DrawingAttributes Ink PacketProperty Stroke

Ink Recognition API (Recognitionn API)

RecognitionAlternate RecognitionAlternates RecognitionProperty Strokes RecognitionResult Recognizer RecognizerContext RecognizerGuide Recognizers WordList

Figure I-4

We list the most common used objects in each category in the following three tables.

Object InkCollector

InkOverlay

Tablet Input API (Pen API) Description The fundamental object used to collect and render ink as it is being entered by the user. InkCollector fires events to your application as they happen and also packages Cursor movements into ink strokes for you. You can tell it what events and what sorts of data you’re interested in receiving, as well as whether you want it to paint ongoing ink strokes as they are collected. A superset of InkCollector that adds selecting and erasing of the ink that’s been captured. For many applications, InkOverlay will be the object of choice to use because its implementation of selection-related features is a real time-saver. Table I-1

Object Ink

Ink Data Management API (Ink API) Description The mother of all ink-related activity, the Ink object is the one indispensable part of any Tablet PC programmer’s arsenal. All digital ink lives within Ink objects, which support a myriad of methods to add and remove ink strokes to and from them. In addition, a key function of Ink objects is to support several hit detection methodologies to determine whether ink has been hit. Finally, Ink objects can save and load themselves from both binary

4

This section is adopted from Rob Jarrett and Philip Su: Building TABLET PC Applications, Microsoft Press, 2002. ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

4

streams and the clipboard. Stroke The Stroke object provides access to a single ink stroke within an Ink object. One of its primary uses is to obtain detailed point-level data about a particular ink stroke, such as its length or pressure. It also supports a small subset of behaviors normally available on an Ink object. Strokes A collection of Stroke objects that implement an eclectic subset of the functionality available through the Ink object. One thing to remember when working with a Strokes object is that it is only a collection of references to ink strokes contained within some Ink object. As a consequence, the object’s strokes don’t have a life of their own independent of the Ink object to which they belong. DrawingAttributes Each Stroke object allows for the setting of its DrawingAttributes, which determines the visual appearance of the ink stroke when drawn on screen. Major characteristics of interest include Color, Transparency, Width, and Antialiased, but there are many other tweaks that can be made to the appearance of Stroke objects. Table I-2

Ink Recognition API (Recognition API) Object Description Recognizer The Recognizer object represents a particular recognition engine installed on the user’s machine. Recognition engines may support one or more languages and may also vary in the features they support. RecognizerContext RecognizerContext objects are the usual means by which you interact with recognition engines to perform ink recognition. An instance of this object is created each time you want ink to be recognized, and any hints about the likely content of the ink are set to give the recognizer its context. When all available information has been given to the RecognizerContext, a call to its Recognize method performs the recognition. RecognitionResult Results from performing recognition are returned in this object. Its primary use is to provide the text that was recognized as well as possible alternative interpretations of the ink. Table I-2

Before we introduce some examples using those APIs, we first review the Microsoft Visual Studio .NET and explain how to include Tablet API in C# applications in part II. Then, we study several examples using Pen API, Ink API, Recognition API, and Ink Control in part III, IV, V, VI, respectively. Further references can be found in part VII.

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

5

Part II. Microsoft Visual Studio .NET In this part, we give a short introduction to Microsoft Visual Studio .NET which we will use to develop Tablet PC applications. Then, we explain how to include Tablet API using .NET with C#. 1. Introduction to .Net Framework The .NET is Microsoft’s new vision for combining the Internet and the Web in the development, engineering and use of software. The major .NET strategy is its independence from a specific language or platform. Developers can create a .NET application in any .NET-compatible language. The Microsoft .NET Framework is at the heart of the .NET strategy. The key to the framework is common language runtime (CLR). Programs are compiled into machinespecific instructions in two steps. The first step is to compile this program into Microsoft Intermediate Language (MSIL), which defines instructions for the CLR. Code converted into MSIL from other languages and sources can be woven together by the CLR. The MSIL code cannot run directly on any computer. We need just-in-time compiler (JITer) to read and produce actual machine code. This provides .NET with a certain amount of platform independence. We can represent the whole procedures in the following figure. Development Tool, such as Visual Studio .Net Source Code: Visual Basic, Visual C++, C# COBOL, etc.

Just-in-time (JIT) compiler Microsoft Intermediate Language (MSIL)

Platformspecific code

Figure II-1

2. Visual Studio .Net Integrated Design Environment (IDE) Visual Studio .Net is Microsoft’s integrated development environment for creating, documenting, running and debugging programs written in a variety of .NET programming languages. Visual Studio .NET organizes programs into projects and solutions. A project is a group of related files, such as C# code, image and documentation. A solution is a group of projects that represent a complete application, or a set of related applications. Each project in the solution may perform a different task. Visual Studio .NET also offers editing tools for manipulating several types of files. Figure II-2 shows the IDE. The upper-right window is the Solution Explorer/Class View/Resource View. This window lists all the files, classes, and resources (including the ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

6

Graph User Interface, GUI) in the solution. The upper-left tab is the Toolbox window if you are currently working GUI. The Toolbox contains reusable software components (Controls) that can be used to customize applications. You can drag controls and drop on your own GUI. The lower-right window is the Properties Window, which allow manipulation of the properties for a form or control. Properties specify information about a control, such as size, color and position. Each control has its own set of properties. The bottom of the Properties Window contains a description of the selected property. The window at the bottom is the Output Window and it will display messages that result from compiling and linking your program.

Figure II-2 3. Using Tablet PC API in Visual Studio .NET5 (a) Create a New Project File Æ New Æ Project. Choose “Visual C# Project” in “Project Types” and “Windows Application” in “Templates”. Specify the Name and Location for this new project. Click “OK” and you will see the .NET IDE becomes Figure II-2.

5

You need to install Table PC Platform SDK first.

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

7

(b) Add Ink API Reference Project Æ Add Reference. Click “Microsoft Tablet PC API” and “Microsoft Tablet PC API v1.5 Components” from the .NET tab and click “Select” button. Then, press “OK” to quit this dialog box.

From the Solution Explorer in .NET IDE, you can see we have added the Table PC API ( Microsoft.Ink and Microsoft.Ink.15) under the “References” folder.

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

8

(c) Add Ink Control Right click on the toolbox window and then click “Customize Toolbox”. The following dialog box will pop up.

Select “InkEdit” and “InkPicture” from the “.NET Framework Components” tab. Press “OK”. You can check the newly added control from the toolbox window.

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

9

Part III. Ink Collection and Display – Pen API In this part, we use two examples to explain how to use the two fundamental Tablet PC input APIs: InkCollector and InkOverlay. 1. InkCollector In this section, we use a very simple example to illustrate how to use InkCollector. (a) Create a new project with name “HelloInk” and add Ink API by following the instructions in Part II-3 (b) Right click on the “Form1.cs” in the “Solution Explorer” window, and then choose “View Code”. Edit the codes as follows6: using using using using using using

System; System.Drawing; System.Collections; System.ComponentModel; System.Windows.Forms; System.Data;

// Æ using Microsoft.Ink;

// We need to use Microsoft.Ink reference

// Å namespace HelloInk { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { /// /// Required designer variable. /// /// private System.ComponentModel.Container components = null;

// add ink collector Æ private InkCollector inkCollector;

// declare InkCollector

// Å public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call //

// add your own codes Æ // set the title shown on top of application Text = "HelloInk"; // construct InkCollector object, send form's handle to // InkCollector, such that InkCollector use this form as the host inkCollector = new InkCollector(Handle); // enable InkCollector to collect pen input inkCollector.Enabled = true;

Notice that “// Add your own code Æ” and “//Å” indicates that you may put some codes in these areas. In this example, we use italic red font for the added codes (to distinguish from the codes already automatically generated by .NET). 6

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

10

// Å } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() // 7 { // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 262); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load); } #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } } }

(c) We can test the result through DebugÆStart in VS .NET IDE menu bar to execute this file. You will see the following dialog box. Use a mouse/pen to write.

7

Click

on

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

to expand this code function.

11

2. InkOverlay In this section, we learn • how to use InkOverlay, • how to design the GUI and the related events, • how to use Color Dialog box. (a) Create a new project with name “InkOverlayDemo” and add Ink API: Follow the instructions in Part II-3. (b) Design GUI: Click on the “Toolbox” window. Drag and drop one “Panel”, one “Button”, and one “ComboBox” control on Form1.

(c) Set properties of each control: (i) Single click on “Panel” control and go to the “Properties” window that is shown on the bottom-left figure. Set “Name” as “pnlInput”,“BackColor” as “White”, and “BorderStyle” as “Fixed3D”. (ii) Click on “Button1”. Set “Name” as “btnColor”. “Text” as “Color”. (iii) Click on “comboBox”. Set “Name” as “cbxEditMode”. “Text” as “Select”. We can see the customized GUI as shown in the bottom-right figure.

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

12

(d) Set events of each control (i) Single click on btnColor button. Click on the properties window. You will see the following figure. To set a reactive code function to respond the clicking event of the button, double click on “Click”. In this way, we have set up the following code function in the Form1.cs: private void btnColor_Click(object sender, System.EventArgs e)

(ii) Single click on cbxEditMode control. To set a reactive code function to respond the selection changed event of the ComboBox control, double click on “SelectedIndexChanged”. In this way, we have set up the following code function in the Form1.cs: private void cbxEditMode_SelectedIndexChanged(object sender, System.EventArgs e)

(e) Right click on the “Form1.cs” in the “Solution Explorer” window, and then choose “View Code”. Edit the codes as follows8: // // // // // //

InkOverlayDemo Reference: · Rob Jarrett and Philip Su: Building TABLET PC Applications, Microsoft Press, p.115~116, 2002 Author: Guan-Ming Su Date: 9/25/2003

using using using using using using

System; System.Drawing; System.Collections; System.ComponentModel; System.Windows.Forms; System.Data;

// Æ using Microsoft.Ink;

// Å namespace InkOverlayDemo { /// /// Summary description for Form1. ///

Notice that “// Add your own code Æ” and “//Å” indicates that you may put some codes in these areas. In this example, we use italic red font for the added codes (to distinguish from the codes already automatically generated by .NET). 8

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

13

public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Button btnColor; private System.Windows.Forms.ComboBox cbxEditMode; private System.Windows.Forms.Panel pnlInput;

// Add you own code here Æ private InkOverlay inkOverlay;

// Å /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call //

// add your own code here Æ // set the title of the application Text = "InkOverlay Demo"; // construct the InkOverlay object, we use pnlInput // as the host window to collect data inkOverlay = new InkOverlay(pnlInput.Handle); // enable InkOverlay to collect pen input inkOverlay.Enabled = true; // fill up all the editing mode of inkoverlay to combobox foreach (InkOverlayEditingMode m in InkOverlayEditingMode.GetValues( typeof( InkOverlayEditingMode))) { cbxEditMode.Items.Add(m); } // cbxEditMode.SelectedItem = inkOverlay.EditingMode;

// Å } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent()

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

14

#endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void btnColor_Click(object sender, System.EventArgs e) {

// Add your own code here Æ // construct Color Dialog box to select color for ink ColorDialog dlgColor = new ColorDialog(); // set the initial color of the color dialog box // to the ink color, dlgColor.Color = inkOverlay.DefaultDrawingAttributes.Color; // Update the color of ink if the user clicks OK if( dlgColor.ShowDialog(this) == DialogResult.OK ) { // set the ink as the selected color from the color dialog box inkOverlay.DefaultDrawingAttributes.Color = dlgColor.Color; }

// Å } private void cbxEditMode_SelectedIndexChanged(object sender, System.EventArgs e) {

// Add your own code here Æ // set the Editing Mode of InkOverlay to the selected item // in the combobox inkOverlay.EditingMode = (InkOverlayEditingMode) cbxEditMode.SelectedItem;

// Å } } }

(f) We can test the result through DebugÆStart in VS .NET IDE menu bar to execute this file. You will see the following dialog box as shown in the below figure (left).

(i) Use pen or mouse to write. You can change the color of ink by clicking “Color” button. Pick a color from the Color Dialog Box as shown in the above figure (middle). (ii) We can select the desired strokes by clicking “Select” on the ComboBox. Use pen to select the strokes. The application will identify those strokes using a rectangle ( ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

15

as shown in the below left figure). You can enlarge it by dragging the boundary of this rectangle.

(iii) We can delete each stoke by choosing “Delete” on the ComboBox, you will see an eraser. Use the eraser to erase the undesired strokes.

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

16

Part IV. Ink Data Management – Ink API 1. Overview In this part, we study the data structure used in the Tablet PC API. There are three classes: Ink, Strokes, and Stroke. Figure IV-1 shows the partial Tablet PC managed library object model. Legend:

Microsoft.Ink

Collection Ink Object Strokes

Stroke

Figure IV-1 Object Model

• •



Ink Objects: Represents the collected strokes of ink within an ink space. Stroke Object: Represents a single ink stroke. Stroke objects are a series of packets9 comprised of (x, y) coordinates and optionally some other packet properties, defined at the time of the Stroke’s creation. One stroke represents exactly one continuous stroke of ink—it cannot have multiple start and end points in it. Strokes Collection: Contains the collection of Stroke objects that represent a single ink stroke. Strokes collections are references to ink data and are not the actual data itself.

We use the example created in Part III-2 to illustrate the relationship among these three classes, which in shown in Figure IV-2. InkOverlay Ink Stroke

Stroke

Ink.Strokes

Stroke

Stroke

InkOverlay.Selection

Strokes

Strokes

Figure IV-2 Relationships among Ink, Stroke, and Strokes 9

Within a stroke, properties (such as the number of points in the stroke) and point data related to that stroke. The set of data sent by the tablet device (digitizer) at each sample point (such as (x,y) coordinates, pen pressure, tilt angle, and rotation angle) in a stroke. The actual packet properties are dependent on the hardware manufacturer and software driver of the tablet device. ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

17

2. Example: PacketStroketViewer In this section, we • learn how to set InkOverlay events, • understand the relationships among packet, stroke, and selection, • learn how to read data from packet, stroke, and selection. (a) Create a new project with name “PacketStrokeViwer” and add Ink API: Follow the instructions in Part II-3. (b) Design GUI: Click on the “Toolbox” window. Drag and drop one “Panel”, one “ListBox”, two “Button”s, and one “ComboBox” control on Form1.

(c) Set properties of each control: (i) Single click on “Panel” control and go to the “Properties” window that is shown on the bottom-left figure. Set “Name” as “pnlInput”,“BackColor” as “White”, and “BorderStyle” as “Fixed3D”. (ii) Click on “Button1”. Set “Name” as “btnColor”. “Text” as “Color”. (iii) Click on “Button2”. Set “Name” as “btnClear”. “Text” as “Clear”. (iv) Click on “ListBox1”. Set “Name” as “lbOutput”. (v) Click on “comboBox”. Set “Name” as “cbxEditMode”. “Text” as “Select”. We can see the customized GUI as shown in the bottom-right figure.

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

18

(d) Set events of each control (i) Single click on btnColor button. Click on the properties window. You will see the following figure. To set a reactive code function to respond the clicking event of the button, double click on “Click”. In this way, we have set up the following code function in the Form1.cs: private void btnColor_Click(object sender, System.EventArgs e)

(ii) Repeat the same procedure for “btnClear” button. We will add one more code function as follows. private void btnClear_Click(object sender, System.EventArgs e)

(iii)Single click on cbxEditMode control. To set a reactive code function to respond the selection changed event of the ComboBox control, double click on “SelectedIndexChanged”. In this way, we have set up the following code function in the Form1.cs: private void cbxEditMode_SelectedIndexChanged(object sender, System.EventArgs e)

(e) Right click on the “Form1.cs” in the “Solution Explorer” window, and then choose “View Code”. Edit the codes as follows10: // // // // // //

InkOverlayDemo PacketStrokeViewer View the packet generated from device and contained in each stroke Author: Guan-Ming Su Date: 9/26/2003

using using using using using using

System; System.Drawing; System.Collections; System.ComponentModel; System.Windows.Forms; System.Data;

// Æ using Microsoft.Ink;

//Å Notice that “// Add your own code Æ” and “//Å” indicates that you may put some codes in these areas. In this example, we use italic red font for the added codes (to distinguish from the codes already automatically generated by .NET).

10

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

19

namespace PacketStrokeViwer { /// /// Summary description for Form1. /// public class Form1 : System.Windows.Forms.Form { private System.Windows.Forms.Panel pnlInput; private System.Windows.Forms.ListBox lbOutput; private System.Windows.Forms.Button btnColor; private System.Windows.Forms.Button btnClear; private System.Windows.Forms.ComboBox cbxEditMode;

// Add your own code here Æ private InkOverlay inkOverlay; int indexX, indexY;

// Å /// /// Required designer variable. /// private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); // // TODO: Add any constructor code after InitializeComponent call //

// Add your own code here Æ // set the title of the application Text = "Packet Stroke Viewer"; // construct the InkOverlay object inkOverlay = new InkOverlay(pnlInput.Handle); // set the desired packet description as (x,Y) locations inkOverlay.DesiredPacketDescription = new Guid [] { PacketProperty.X, PacketProperty.Y }; // Hook up to the InkOverlay's event handlers: // new cursor button down arriving event inkOverlay.CursorButtonDown += new InkCollectorCursorButtonDownEventHandler ( inkOverlay_CursorButtonDown ); // Hook up to the InkOverlay's event handlers: // new packet arriving event inkOverlay.NewPackets += new InkCollectorNewPacketsEventHandler( inkOverlay_NewPacket ); // Hook up to the InkOverlay's event handlers: // new stroke arriving event inkOverlay.Stroke += new InkCollectorStrokeEventHandler( inkOverlay_Stroke ); // Hook up to the InkOverlay's event handlers: // selection changed event inkOverlay.SelectionChanged += new InkOverlaySelectionChangedEventHandler( inkOverlay_SelectionChanged ); // disable InkOverlay to set packet properties inkOverlay.Enabled = false; //Save the X and Y data locations within the packet data. GetXYIndexes(ref indexX, ref indexY); // enable InkOverlay to collect pen input inkOverlay.Enabled = true; // fill up all the editing mode of inkoverlay to combobox foreach (InkOverlayEditingMode m in

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

20

InkOverlayEditingMode.GetValues( typeof( InkOverlayEditingMode))) { cbxEditMode.Items.Add(m); } // set the combobox as the current invOverlay editing mode cbxEditMode.SelectedItem = inkOverlay.EditingMode;

// Å } /// /// Clean up any resources being used. /// protected override void Dispose( bool disposing ) { if( disposing ) { if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows Form Designer generated code /// /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// private void InitializeComponent() #endregion /// /// The main entry point for the application. /// [STAThread] static void Main() { Application.Run(new Form1()); } private void btnColor_Click(object sender, System.EventArgs e) {

// Add your own code here Î // construct Color Dialog box to select color for ink ColorDialog dlgColor = new ColorDialog(); // set the initial color of the color dialog box // to the ink color, dlgColor.Color = inkOverlay.DefaultDrawingAttributes.Color; // Update the color of ink if the user clicks OK if( dlgColor.ShowDialog(this) == DialogResult.OK ) { // set the ink as the selected color from the color dialog box inkOverlay.DefaultDrawingAttributes.Color = dlgColor.Color; }

// Å } private void btnClear_Click(object sender, System.EventArgs e) {

// Add your own code here Î // delete all strokes in the panel inkOverlay.Ink.DeleteStrokes(); // clear up the panel pnlInput.Invalidate(); // delete all items in the list box

ENEE408G Fall 2003 (Update: 10/7/2003) Tablet PC Programming Manual

21

lbOutput.Items.Clear();

// Å } private void cbxEditMode_SelectedIndexChanged( object sender, System.EventArgs e) {

// Add your own code here Î inkOverlay.EditingMode = (InkOverlayEditingMode) cbxEditMode.SelectedItem; //