Most applications will require some form of text input. By using the ITextInputPanel API you can optimize the pen text-input experience on Tablet PCs.

If you have ever used a Tablet PC, you have most likely used Tablet PC Input Panel. Input Panel is the handwriting input tool that lies on top of your application so that you can insert handwritten text into any non-ink enabled Microsoft® Windows® control. Using Input Panel programmability is a great way to ensure that Input Panel provides the best possible pen input user experience in your application.

Users can choose from two main ways to access the Input Panel in the Windows Vista™ operating system. You can either tap the Input Panel tab, which is located on the left or right edge of screen, or you can tap the icon that appears whenever you use your pen to give focus to a text field. When you launch Input Panel using the second approach, Tablet PC uses several parameters to decide how to display Input Panel, such as the placement of the text box relative to the screen edges, the size and text entry mode from the last time you used Input Panel, and whether the text box is a password field. Most of the time Input Panel will do a good enough job with this, but what if you want Input Panel to interact in a more customized way with your application? This is where Input Panel programmability comes into the picture.

In Windows Vista you can use the new ITextInputPanel API, with either unmanaged or managed code, to tell Input Panel how you want it to behave around the controls in your application. The properties with “Preferred” in their name allow you to set preferred behavior for Input Panel. The nice thing about setting preferred behavior is that Input Panel will still make sure that it is always in a usable state. For example, if you set Input Panel to preferably appear above a certain text box and the user has moved the window to where the text box is located at the top of the screen, Input Panel will automatically make sure that it is visible by placing itself below the text box instead. In addition to setting preferred behaviors, you can manually specify Input Panel’s exact screen position. When you do this, Input Panel places itself exactly where you specify; therefore, you are responsible for positioning it on the screen and making sure it is visible.

Programmability Possibilities

Using the ITextInputPanel API is a great way to make your application work even better on Tablet PCs. I’ll quickly summarize some of the main things the API allows you to do before I take a look at how to use it:

Set absolute position of Input Panel.

Set preferred direction-you can set the preferred direction of where Input Panel should appear relative to your controls (on the top or bottom of the control).

Set visibility-you can choose not to show Input Panel for certain controls.

Set expanded state-make Input Panel go straight to the expanded state when a control gets focus.

Set default input area-select any of the three input areas as the default for a control (writing pad, character pad, or on-screen keyboard).

Look up Input Panel properties such as size, current input area, or current correction mode.

Listen to event changes of the Input Panel state.

Collect Ink objects through Input Panel in addition to the recognized text.

So what can you do with all of this? You can make sure that Input Panel doesn’t cover essential parts of your user interface while it is in use, for example. Or you can set Input Panel to expand as soon as your controls get focus, which saves pen input users time and effort each time they want to add text to a field. If you have a text field where the users always enter a mix of characters and numbers that you know isn’t a good fit for handwriting, e.g., a license plate number, you can automatically switch Input Panel to keyboard mode and save the users the hassle of switching back and forth.

The ability to capture ink and recognition results as they are sent from Input Panel to the controls in your application also opens up a lot of possibilities. You can analyze or save users’ ink data from Input Panel or you could even alter their input, for example, to automatically expand shorthand into full words.

Using the ITextInputPanel API

Figure 1 shows a sample where I’ve added some custom Input Panel behavior to a simple form. I set all three text boxes to interact differently with Input Panel. For the first text box, I want Input Panel to appear over the box, so that Input Panel doesn’t cover the text boxes below. I also want it to expand as soon as the control gets focus. I will set the second text box to always hide the Input Panel when it gets focus. This could be useful if users enter the ID# using another input method, such as a barcode scanner. Finally, I will set the last text box to expand Input Panel in keyboard input mode so that the user can quickly enter the age using the number keys.

The code in Listing 1 shows how you can achieve the wanted behavior by using C# and the managed ITextInputPanel API. The first thing you have to do to be able to use Input Panel programmability features is to add a reference to the Microsoft.Ink DLL. It should appear in the list of .NET components under the name “Microsoft Tablet PC API” (version 6.0 or higher). Next add a using statement for Microsoft.Ink.TextInputPanel, and then you’ll be ready to use the TextInputPanel object to manipulate Input Panel.

Conclusion

I hope this article has given you a little insight into the possibilities of the ITextInputPanel API and how you can utilize it to make sure your Tablet PC application provides a great Input Panel user experience. Customizing your application to work well with Input Panel has many advantages, especially if you know that many of your clients will use Input Panel to enter text. With only a few lines of code you can make big user experience improvements. Maybe your application works great 90% of the time with the Input Panel default settings, but making sure it works perfectly for the last 10% can make the difference between a user and a happy user.