Browse DevX
Sign up for e-mail newsletters from DevX


Creating Tablet PC Applications with VS .NET : Page 3

The Tablet PC platform supports applications with special tablet features enabled, such as ink input and pen-based operation. In order for this platform to become truly popular, third-party vendors will also have to ink-enable their applications. Find out how.




Building the Right Environment to Support AI, Machine Learning and Deep Learning

The InkOverlay Class
The InkOverlay class is very straightforward to use. Simply create a new Visual Studio .NET Windows Forms project, and add the Microsoft.Ink assembly to your project references (this assembly is installed in the GAC once you install the Ink SDK). Then, open the Code window form, the automatically created Form1 class, and add a reference for the ink collector on the form level:

Private Microsoft.Ink.InkOverlay oInk;

This is the C# version. If you created your project in VB.NET, use the following line:

Private oInk As _ Microsoft.Ink.InkOverlay

Now, add code to the form's constructor to enable the ink collector. The object operates by attaching itself to the handle of any control on a Windows form. You can use the form's handle and assign it to the ink collector before you enable the collector for pen input:

public Form1() { InitializeComponent(); // We load and initiate the // InkOverlay object this.oInk = new Microsoft.Ink.InkOverlay(); this.oInk.Handle = this.Handle; this.oInk.Enabled = true; }

Note that I am using fully qualified names (like Microsoft.Ink.InkOverlay, rather than just InkOverlay). You can avoid having to do that by adding a generic reference to the namespace at the top of your program or in your project settings.

Once again, the Visual Basic .NET version is very similar:

Public Sub New() MyBase.New() InitializeComponent() ' We load and initiate the ' InkOverlay object Me.oInk = new _ Microsoft.Ink.InkOverlay() Me.oInk.Handle = Me.Handle Me.oInk.Enabled = True End Sub

As you can see, the difference between the C# and the Visual Basic .NET version is minimal. Therefore, I will focus on the C# version unless there is a significant difference. You won't have a hard time converting the samples to VB .NET if that is the language of your choice. Also, you can download the samples in a VB.NET version from the CoDe Magazine Web site.

OK, this is it! You just created your first ink-enabled application. When you launch this form, the form is immediately ready to collect ink input (Figure 4). Of course in many scenarios, you may not want the entire form to be ink enabled. For instance, if you were to write a simple ink notepad application, you may want the majority of the form to be ink enabled, but you may have other controls on the form, such as toolbar buttons, and a status bar. For this reason, it is often better to add a control (such as a Panel) to the form for the specific purpose of collecting ink. Figure 5 shows the same form with an added panel. To make it look a bit more like a sheet of paper that ink can be applied to, I also set the background of the panel to white. Attaching the InkOverlay to the panel only is just as easy as attaching it to the entire form:

public Form1() { InitializeComponent(); // We load and initiate the // InkOverlay object this.oInk = new Microsoft.Ink.InkOverlay(); this.oInk.Handle = this.panel1.Handle; this.oInk.Enabled = true; }

At this point, you have a simple ink notepad that can be used to take simple handwritten notes. However, the application is not very sophisticated. For instance, you may want to change the color of the ink you write with. Setting this characteristic (as well as a number of other attributes) can be achieved easily using the DefaultDrawingAttributes object on the InkOverlay. The following code shows how I attached a color-picker button:

private void btnColor_Click(object sender, System.EventArgs e) { // We use a color dialog to let the // user select the pen color ColorDialog oDlg = new ColorDialog(); oDlg.Color = oInk.DefaultDrawingAttributes.Color; oDlg.ShowDialog(this); oInk.DefaultDrawingAttributes.Color = oDlg.Color; }

In this example, you use the native .NET Framework Color Picker dialog box, assign it the current drawing color as the initially selected color, let the user pick a different color, and then re-assign the new color as the new drawing attribute.

Figure 4: The entire form is ink-enabled, thanks to the InkOverlay class.
Figure 5: Here is a simple ink notepad developed in VS.NET.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date