|
//
// Basic Ink enabled Windows Forms application with
// handwriting recognition using RecognizerContext
// Gavin Gear - http://blogs.msdn.com/gavingear
// 08/2006
//
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using Microsoft.Ink; // The managed Tablet PC API
namespace BasicInkApplication
{
public partial class BasicInkApplication : Form
{
// The InkOverlay that we'll attach to our Form
private InkOverlay inkOverlay;
private Recognizers recognizers;
public BasicInkApplication()
{
InitializeComponent();
// Create an InkOverlay object that's attached to the Form
this.inkOverlay = new InkOverlay(this);
// Enable the InkOverlay (default is Enabled == false)
this.inkOverlay.Enabled = true;
// The InkOverlay needs to be disposed due to unmanaged resources
// used by the InkOverlay
this.FormClosing += new FormClosingEventHandler(BasicInkApplication_FormClosing);
// Populate the recognizers dropdown with the recognizers
// that are installed on the system
recognizers = new Recognizers();
foreach (Recognizer reco in recognizers)
{
int index = this.comboBoxRecognizers.Items.Add(reco.Name);
}
this.comboBoxRecognizers.SelectedIndex = 0;
}
void BasicInkApplication_FormClosing(object sender, FormClosingEventArgs e)
{
this.inkOverlay.Dispose();
}
private void buttonRecognize_Click(object sender, EventArgs e)
{
// Instantiate a RecognizerContext object using the
// Recognizer.CreateRecognizerContext() method where
// we are using the selected index of the ComboBox
// to get the corresponding recognizer from the Recognizers
// collection
RecognizerContext context =
this.recognizers[this.comboBoxRecognizers.SelectedIndex].CreateRecognizerContext();
// Add the strokes collected by our InkOverlay
context.Strokes = this.inkOverlay.Ink.Strokes;
// Perform recognition, pass a RecognitionStatus object
// that will give the status of the recognition
RecognitionStatus status;
RecognitionResult result = context.Recognize(out status);
MessageBox.Show(result.TopString);
context.Dispose(); // Free the unmanaged resources
}
}
} |