Yes, more PDC swag :)
I spent a half hour in a hands-on lab today, learning how to program for the tablet PC in Windows Vista and Visual Studio 2005. In return for doing something which I considered to be enjoyable and enlightening, I received a refurbished Wacom Graphire 4x5 Tablet, and a 256mb memory stick with all the labs. Pretty nice!
It is much easier to program for ink and handwriting recognition than you might think. In fact, there is very little code you have to write. For example, this code is sufficient to allow you to start drawing within a group box on a Windows form:
// Create a new InkOverlay and assign it to the Handle
// of the GroupBox (groupBox1)
inkOverlay1 = new InkOverlay(groupBox1.Handle);
// Enable the InkOverlay to collect ink
inkOverlay1.Enabled = true;
Et, Voila! You can draw pretty pictures until your heart's content. That code, and the code below, are both from the great hands-on lab.
Actual handwriting recognition is a little bit more work, but still far fewer lines of code than I might have thought:
// Create the empty strokes collection to recognize
strokesToRecognize = inkOverlay1.Ink.CreateStrokes();
// Create the Recognizer Context to do the Recognition
foreach (Recognizer recognizer in new Recognizers())
if (recognizer.Name == "Microsoft English (US) Handwriting Recognizer")
recognizerContext = recognizer.CreateRecognizerContext();
recognizerContext.Strokes = strokesToRecognize;
// Handle the InkOverlay's Stroke event to recognize the Ink
inkOverlay1.Stroke += new InkCollectorStrokeEventHandler(inkOverlay1_Stroke);
// Handle the Recognizer Context's Recognition event
if (recognizerContext != null)
recognizerContext.Recognition += new RecognizerContextRecognitionEventHandler(recognizerContext_Recognize);
// Handle the InkOverlay's Stroke event
// This event fires every time a stroke is collected on the ink overlay
private void inkOverlay1_Stroke(object sender, Microsoft.Ink.InkCollectorStrokeEventArgs e)
// Get the Stroke from the Event Args
Stroke stroke = e.Stroke;
// Handle the Recognizer Context's Recognize event
// This event fires everytime the Recognizer Context recognizes a new stroke
private void recognizerContext_Recognize(object sender, Microsoft.Ink.RecognizerContextRecognitionEventArgs e)
// When the recognition occurs, take the recognized text and place it
// in the text box.
textBox2.Text = e.Text;
And that's it. You now have handwriting recognition that spits the recognized text out to textBox2. Pretty amazing stuff.
Off to the Universal Studios party. Either tonight when I get back, or tomorrow, I'll post more about what XAML is and why XAML is so important, why I'm really excited about Microsoft Expression (Acrylic, Quartz, and Sparkle) and why WPF is absolutely the wave of the future.