Advertisement
joapaspe

InkOverlay Timer

Mar 16th, 2012
99
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 4.80 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9. using Microsoft.Ink;
  10. namespace pruebaTablet
  11. {
  12.     public partial class Form1 : Form
  13.     {
  14.         InkOverlay inkOverlay;
  15.        
  16.         public Form1()
  17.         {
  18.             InitializeComponent();
  19.  
  20.         }
  21.  
  22.         private void Form1_Load(object sender, EventArgs e)
  23.         {
  24.             inkOverlay = new InkOverlay();
  25.             inkOverlay.Handle = this.Handle;
  26.             inkOverlay.Enabled = true;
  27.             inkOverlay.Gesture += new InkCollectorGestureEventHandler(Event_OnApplicationGesture);
  28.             inkOverlay.CollectionMode = CollectionMode.InkAndGesture;
  29.             inkOverlay.SetGestureStatus(ApplicationGesture.Left, true);
  30.             inkOverlay.SetGestureStatus(ApplicationGesture.Right, true);
  31.             inkOverlay.SetGestureStatus(ApplicationGesture.Up, true);
  32.             inkOverlay.SetGestureStatus(ApplicationGesture.Down, true);
  33.             inkOverlay.SetGestureStatus(ApplicationGesture.Check,true);
  34.  
  35.             // timer configuration
  36.             timer1.Interval = 500;
  37.             this.inkOverlay.Stroke += new InkCollectorStrokeEventHandler(Event_Stroke);
  38.  
  39.  
  40.         }
  41.  
  42.         private void timer1_Tick(object sender, EventArgs e)
  43.         {
  44.             timer1.Stop();
  45.  
  46.             //Recognition
  47.             Recognizers recs = new Recognizers();
  48.             Recognizer reco = recs.GetDefaultRecognizer();
  49.             RecognizerContext context = reco.CreateRecognizerContext();
  50.             context.Strokes = inkOverlay.Ink.Strokes;
  51.  
  52.             RecognitionStatus status = RecognitionStatus.NoError;
  53.             RecognitionResult res = context.Recognize(out status);
  54.  
  55.             if (status == RecognitionStatus.NoError)
  56.             {
  57.                 MessageBox.Show(res.TopAlternate.ToString());
  58.  
  59.             }
  60.  
  61.             //Cleaning the strokes
  62.             inkOverlay.Ink.DeleteStrokes(inkOverlay.Ink.Strokes);
  63.             inkOverlay.Ink.Strokes.Clear();
  64.  
  65.             Invalidate();
  66.         }
  67.  
  68.         private  void Event_Stroke(object Sender, InkCollectorStrokeEventArgs e){
  69.  
  70.             InkOverlay myInk = (InkOverlay) Sender;
  71.  
  72.             if (myInk.Ink.Strokes.Count == 1)
  73.             {
  74.                 timer1.Start();
  75.                    
  76.             }
  77.         }
  78.  
  79.  
  80.         private void button1_Click(object sender, EventArgs e)
  81.         {
  82.  
  83.             Recognizers recs = new Recognizers();
  84.             Recognizer reco = recs.GetDefaultRecognizer();
  85.             RecognizerContext context = reco.CreateRecognizerContext();
  86.             context.Strokes = inkOverlay.Ink.Strokes;
  87.  
  88.             RecognitionStatus status = RecognitionStatus.NoError;
  89.             RecognitionResult res = context.Recognize(out status);
  90.  
  91.             if (status == RecognitionStatus.NoError)
  92.             {
  93.                 MessageBox.Show(res.TopAlternate.ToString());
  94.  
  95.             }
  96.  
  97.             //Cleaning the strokes
  98.             inkOverlay.Ink.DeleteStrokes(inkOverlay.Ink.Strokes);
  99.             inkOverlay.Ink.Strokes.Clear();
  100.  
  101.             Invalidate();
  102.            
  103.         }
  104.  
  105.         void Event_OnApplicationGesture(object sender, InkCollectorGestureEventArgs e)
  106.         {
  107.             Gesture G = e.Gestures[0];
  108.  
  109.             // we will use the gesture if it has confidence of strong or intermediate
  110.  
  111.             if (G.Confidence == RecognitionConfidence.Intermediate ||
  112.                 G.Confidence == RecognitionConfidence.Strong)
  113.             {
  114.  
  115.                 switch (G.Id)
  116.                 {
  117.                     case ApplicationGesture.Left:
  118.                         MessageBox.Show("Left");
  119.                         break;
  120.                     case ApplicationGesture.Right:
  121.                         MessageBox.Show("Right");
  122.                         break;
  123.                     case ApplicationGesture.Up:
  124.                         MessageBox.Show("Up");
  125.                         break;
  126.                     case ApplicationGesture.Down:
  127.                         MessageBox.Show("Down");
  128.                         break;
  129.                     case ApplicationGesture.Check:
  130.                         MessageBox.Show("Check");
  131.                         break;
  132.                 }
  133.             }
  134.  
  135.         }
  136.  
  137.  
  138.         private void button2_Click(object sender, EventArgs e)
  139.         {
  140.             string info = "";
  141.  
  142.             info += String.Format("There are {0} strokes.\n", inkOverlay.Ink.Strokes.Count);
  143.             foreach(Stroke stroke in inkOverlay.Ink.Strokes){
  144.                 info+= String.Format("Stroke has {0} points.\n",stroke.GetPoints().Length);
  145.             }
  146.  
  147.             MessageBox.Show(info);
  148.  
  149.            
  150.            
  151.         }
  152.  
  153.  
  154.        
  155.  
  156.        
  157.  
  158.  
  159.  
  160.     }
  161. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement