Working with Ink
The InkCollector.Ink property contains the Ink that is written to the surface of the containing WinControl. The InkCollector.Ink.Strokes property contains all the Strokes made by the stylus. Again, a Stroke is a continuous movement of the stylus, from the point where the stylus touches the screen to where the stylus is removed from the screen. As shown in Listing 3, you use the InkCollector.Ink.Strokes.ToString() method to perform handwriting recognition.
Listing 3 Code for the sample apps Recognize menu item
private void recognizeToolStripMenuItem_Click(object sender, EventArgs e) { //Do the handwriting recognition string str = inkCollector.Ink.Strokes.ToString(); if(str != null && str.Length>0) { MessageBox.Show(str); }else { MessageBox.Show("Cannot recognize handwriting"); } }
Once the application has done the Ink recognition, you reset the application’s Ink recognition capability by deleting the Strokes collection of the InkCollector.Ink object and refreshing the surface of the WinForm control that is the container for the InkCollector. Listing 4 shows you the Clear menu item click handler that clears stylus writing from the application’s surface.
Listing 4 Clear menu item click event handler and Clear() method
private void clearToolStripMenuItem_Click(object sender, EventArgs e) { this.Clear(); } private void Clear() { //Clear out the strokes that you made on the surface inkCollector.Ink.DeleteStrokes(); //Clear the writing surface panel of the ink rendering pnlWritingSurface.Refresh(); }