Derik Whittaker

Syndication

News


Images in this post missing? We recently lost them in a site migration. We're working to restore these as you read this. Should you need an image in an emergency, please contact us at imagehelp@codebetter.com
Using Microsoft.Ink with a WordList

Not sure how many of you have needed to use the Microsoft.Ink SDK, but I am currently learning how to use the SDK on my current project.  I have to say, that the reconizition that they provide is really, really good.

The Ink SDK comes with a TextBox and a PictureBox, but I only need the Text Box, so that is what I will work with here.  When using the TextBox, it is almost as straight forward as the standard TextBox, but you will need to set a few properties before you can achive the results you are looking for.

In this post I will show you how to setup a InkText Box for recognition with Wordlist Validation.  So lets get started.

Step 1 - Creating the Recognizer Context 

// Create the local context recognization, this will be used during the recognition

private RecognizerContext _context = new RecognizerContext();

 

Step 2 - Wired up the needed events

// Needed for the recognition to actuall kick off

inkEdit.Recognition += new InkEditRecognitionEventHandler( inkEdit_Recognition );

 

// Needed so we can run recognition with alternates
Context.RecognitionWithAlternates += new RecognizerContextRecognitionWithAlternatesEventHandler( Context_RecognitionWithAlternates );


Step 3 - Setting some default properties on your InkEdit TextBox

// This needs to be set to define the mode the control is in.

//    We do not want to listen for gestures, so we dont use InkAndGesture

this.inkEdit.InkMode = Microsoft.Ink.InkMode.Ink;

 

// When writing in the text box the controll will not perform immediate reconigition so this

//   tells the controll how long to wait before it attemps to reconize your handwriting to text

this.inkEdit.RecoTimeout = 1000;

 

// If you dont set this to true, you will not be able to use the mouse to 'write'

this.inkEdit.UseMouseForInput = true;

 

Step 4 - Prepare the Context and word list.
 

// Create the recognization

Context = new RecognizerContext();

 

// The wordlist object here needs to be populated by you with the list of valid values

//   that can be reconized.  This can be a list of zip codes for example

Context.WordList = wordList;

 

// If using a word list, then the factoid needs to be set to WordList

Context.Factoid = Factoid.WordList;

 

Context.RecognitionFlags = RecognitionModes.WordMode | RecognitionModes.Coerce;

 

Step 5 - Code for the recognition

// copy the strokes from the InkEdit control into the new

// RecognizerContext

Context.Strokes = e.RecognitionResult.Strokes.Ink.Clone().Strokes;

 

// Kickoff the bacground recognization

Context.BackgroundRecognizeWithAlternates();

 

Step 6 - Listen ot the background recognition

private void Context_RecognitionWithAlternates( object sender, RecognizerContextRecognitionWithAlternatesEventArgs e )

{

 

    // Because the background recogizition runs on a seperate thread, we need to check for

    //   invoke so we dont do cross thread calls.

    if ( InvokeRequired )

    {

        BeginInvoke( new RecognizerContextRecognitionWithAlternatesEventHandler( Context_RecognitionWithAlternates ), sender, e );

        return;

    }

 

    //  I clear the values, because i only want valid data from the word list.

    inkEdit.Clear();

 

    // I only want to allow valid data in my Ink Text Box, so if the confidence is Poor, then i will clearn

    //   the values

    if ( e.Result.TopConfidence != RecognitionConfidence.Poor )

    {

 

        // Since we have a solid confidence level, set the top match value

        inkEdit.SelectedText = e.Result.TopString;

        inkEdit.SelectionStart = inkEdit.SelectionStart + e.Result.TopString.Length;

    }

    else

    {

 

        // Clearing the text box because we only allow values that have a solid confidence level

        inkEdit.SelectedText = string.empty;

 

        // If you wanted to do something with the alternate values from the wordlist, do i there

        HandleAlternates( e.Result.GetAlternatesFromSelection() );

    }

}



Well there you have it, a clean cut example to using the Microsoft.Ink text box with WordList Recognition.

Posted 10-24-2006 6:33 AM by Derik Whittaker
Filed under: , , ,

[Advertisement]

Comments

Constantinos wrote re: Using Microsoft.Ink with a WordList
on 04-13-2007 6:15 AM

interesting

Spiridon wrote re: Using Microsoft.Ink with a WordList
on 04-15-2007 9:14 AM

Cool}Cool!

Pericles wrote re: Using Microsoft.Ink with a WordList
on 04-15-2007 2:14 PM

Nice

Stratis wrote re: Using Microsoft.Ink with a WordList
on 04-17-2007 5:58 PM

Interesting...

Vasilis wrote re: Using Microsoft.Ink with a WordList
on 04-18-2007 2:21 AM

Nice!

Ivan wrote re: Using Microsoft.Ink with a WordList
on 04-18-2007 2:30 AM

Nice

Costa wrote re: Using Microsoft.Ink with a WordList
on 04-18-2007 9:18 AM

Nice...

Metrophanes wrote re: Using Microsoft.Ink with a WordList
on 04-18-2007 8:37 PM

Nice...

Yiorgos wrote re: Using Microsoft.Ink with a WordList
on 04-19-2007 4:35 AM

Cool}Cool!

Costas wrote re: Using Microsoft.Ink with a WordList
on 04-19-2007 6:53 AM

Nice...

Ambrosios wrote re: Using Microsoft.Ink with a WordList
on 04-19-2007 7:42 AM

Nice

Stelios wrote re: Using Microsoft.Ink with a WordList
on 04-19-2007 9:42 AM

Nice!

About The CodeBetter.Com Blog Network
CodeBetter.Com FAQ

Our Mission

Advertisers should contact Brendan

Subscribe
Google Reader or Homepage

del.icio.us CodeBetter.com Latest Items
Add to My Yahoo!
Subscribe with Bloglines
Subscribe in NewsGator Online
Subscribe with myFeedster
Add to My AOL
Furl CodeBetter.com Latest Items
Subscribe in Rojo

Member Projects
DimeCasts.Net - Derik Whittaker

Friends of Devlicio.us
Red-Gate Tools For SQL and .NET

NDepend

SlickEdit
 
SmartInspect .NET Logging
NGEDIT: ViEmu and Codekana
LiteAccounting.Com
DevExpress
Fixx
NHibernate Profiler
Unfuddle
Balsamiq Mockups
Scrumy
JetBrains - ReSharper
Umbraco
NServiceBus
RavenDb
Web Sequence Diagrams
Ducksboard<-- NEW Friend!

 



Site Copyright © 2007 CodeBetter.Com
Content Copyright Individual Bloggers

 

Community Server (Commercial Edition)