|
//
// 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 RecognizerContext recognizerContext;
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);
this.recognizerContext = new RecognizerContext();
this.recognizerContext.Recognition +=
new RecognizerContextRecognitionEventHandler(recognizerContext_Recognition);
}
void BasicInkApplication_FormClosing(object sender, FormClosingEventArgs e)
{
this.recognizerContext.Dispose();
this.inkOverlay.Dispose();
}
// Kick off background recognition if we have strokes to recognize
private void buttonRecognize_Click(object sender, EventArgs e)
{
if(this.inkOverlay.Ink.Strokes.Count > 0)
{
// Add the strokes collected by our InkOverlay
this.recognizerContext.Strokes = this.inkOverlay.Ink.Strokes;
this.recognizerContext.BackgroundRecognize();
}
else
{
MessageBox.Show("No strokes to recognize...");
}
}
// Handle the Recognition event - this event is raised when
// RecognizerContext.BackgroundRecognize() finishes
void recognizerContext_Recognition(
object sender,
RecognizerContextRecognitionEventArgs e)
{
if (e.RecognitionStatus != RecognitionStatus.NoError)
{
MessageBox.Show(
"Error(s) were reported during recognition: " +
Environment.NewLine +
e.RecognitionStatus.ToString());
}
else
{
MessageBox.Show(
"Result from recognition:" +
Environment.NewLine +
e.Text);
}
}
}
} |