Master C# Logo banner
Welcome to MasterCSharp.com - Master C#, the easy way... - by Saurabh Nandu

 


Introduction to Tablet PC Development

Add Comment
 

 
<span class=wboxheado>Introduction</span><br> Microsoft has been on the forefront of new ways user interactivity with the computer. The Tablet PC is the result of one of those efforts to bring the computer much closer to the users comfort. Microsoft launched the Tablet PC OS along with hardware recommendations to Tablet PC manufacturers to insure end users get the best experience out of the platform. <p>Although its certainly a great platform and form factor, I believe that its not been successfully marketed. Even after 2 years of the tablets being in market, users still have the questions like Will Tablet PCs be mainstream?, Are Tablet PCs very expensive?, Tablet PCs are for a niche market, right?, I am sure the Tablet cant recognize my ****ed handwriting!. Last December (2004), I was in the US during Christmas time in San Francisco, California. I visited some local computer stores like Frys, Best Buys etc. around the Pleasanton-Freemont area and I did not find a single Tablet PC on display, making me wonder what the Tablet PC marketing has been doing! <p> <span class=wboxheado>So what's a Tablet PC?</span><br> Well there are dedicated websites like the <a class="wbox" target="_blank" href="http://www.thetabletpcbuzz.com">Tablet PC Buzz</a>&nbsp; <a class="wbox" target="_blank" href="http://thetabletpc.net"> TheTabletPC.Net</a> etc. that can fill you in with the gory details. To be brief, a Tablet PC is a platform on which one of the modes of input is a Pen. Remember the last time you took a Pen and wrote something long (I hope you are not recoiling way back to your college days like me); well the Tablet PC is a platform to give you the same experience with a geeky edge to it! Now it gives you the reason to walk into a meeting with your Tablet PC and use it to WRITE notes, draw (drawing stick figures of your boss :) ) and still not be rude! Other than that is an awesome platform for the Health Care, Insurance, ___ (Insert any of todays paper driven industry) to start adopting digital paper. <p> <span class="wboxheado">How do I get started to develop applications for the Tablet PC?</span><br> You could start by convincing your boss (which could be your wife), to get you a Tablet PC! Although thats not absolutely necessary to have a Tablet PC to get started! You can develop and test (to some extent) pen-enabled applications (i.e. applications for the Tablet PC) on your normal workstation/laptop.<br> All you really need is:<br> 1) Windows 2000 (Sp4), Windows Server 2003, Windows XP Professional, Windows Tablet PC <br> 2) .NET SDK v1.1 (VS 2003 will help, although not 100% necessary) considering you want to develop in C#. <br> 3) Tablet PC SDK Latest is version 1.7 (15MB) [ <a class="wbox" target="_blank" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=B46D4B83-A821-40BC-AA85-C9EE3D6E9699&displaylang=en"> http://www.microsoft.com/downloads/details.aspx?FamilyId=B46D4B83-A821-40BC-AA85-C9EE3D6E9699&amp;displaylang=en</a> ] Please read the notes on the download page. <br> 4) Setup the paths to the Tablet PC SDK libraries as given at the following link<br> [ <a class="wbox" target="_blank" href="http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dntablet/html/tabdevfaq.asp?frame=true"> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dntablet/html/tabdevfaq.asp?frame=true</a> ]<br> Once you have the Tablet PC SDK installed, paths setup you are all set to start developing pen-enabled applications.<p> <span class="wboxheado">The first Pen Enabled application</span><br> <span class="wboxhead">1) Simple Windows Form</span><br> The first pen-enabled application I will build will show you how Ink (more on this a little later) can be used to draw/write on a Windows Form. <br> To start with fire-up your favorite editor (notepad/emacs) and punch in (copy/paste) the code below. As you will observe its simple code from <b>FirstApp.cs</b> that will display a Windows Form.<br> &nbsp;<table border="0" width="100%" class="code" cellspacing="0" cellpadding="0"> <tr> <td width="100%"> <pre> using System ; using System.Windows.Forms ; namespace MasterCSharp.TabletPC.Samples { public class FirstApp : Form { public static void Main() { Application.Run( new FirstApp() ); } } }</pre></td></tr></table> <br> And then compile it with <i>csc FirstApp.cs</i> to produce <i>FirstApp.exe</i> application.<p> <span class="wboxhead">2) Adding Ink Collector object</span><br> In order for the sample application to be able to collect ink the Tablet PC SDK defines a control called the <b>InkCollector</b> (Microsoft.Ink namespace). This control can be attached to another control on which you want to capture ink. In our first sample I attach the <i>InkCollector</i> to the main Form so that I can collect ink from the form.<br> &nbsp;</p> <table border="0" width="100%" class="code" cellspacing="0" cellpadding="0"> <tr> <td width="100%"> <pre> using System ; using System.Windows.Forms ; using Microsoft.Ink ; namespace MasterCSharp.TabletPC.Samples { public class FirstApp : Form { private InkCollector inkCollect ; public FirstApp() { inkCollect = new InkCollector(this); inkCollect.Enabled = true ; } public static void Main() { Application.Run( new FirstApp() ); } protected override void Dispose( bool disposing ) { if( disposing ) { if( inkCollect != null ) inkCollect.Dispose(); } base.Dispose( disposing ); } } }</pre> </td> </tr> </table> <p>If you look at the code above the first thing I have done is referenced the <b>Microsoft.Ink</b> namespace. The assembly corresponding to this is <i>Microsoft.ink.dll</i>, which generally resides in the C:\Program Files\Microsoft Tablet PC Platform SDK\Include directory. <br> Next, within the class I have defined a member of type <b>InkCollector</b>. When the member <i>inkCollect</i> is instantiated, I pass <b>this</b> indicating that I want the <i>InkCollector</i> control to be attached to the Form. Finally, I set <i>inkCollect</i>s <b>Enabled</b> property to true indicating that the control should start collecting ink. <br> One important point to note is that the <i>InkCollector </i>control internally depends upon unmanaged resources (COM objects) hence it is essential to manually free the resources once the control is no longer required. Hence I override the <b>Dispose</b> method on the Form and dispose the <i>inkCollect</i> object. <br> <br> Now lets compile this application using <i>csc /r:Microsoft.ink.dll FirstApp.cs</i> <br> <br> <b>Note:</b> <i>If compilation fails make sure you have setup the correct paths as mentioned above. You can also you the following command to compile the application:<br> csc /r:&quot;C:\Program Files\Microsoft Tablet PC Platform SDK\Include\microsoft.ink.dll&quot; FirstApp.cs</i><br> <br> Now run the application calling <i>FirstApp</i> at the command prompt. You will see the normal blank Form, but observe the cursor it will be displayed as a dot. You can use you mouse to write/draw on the Form using Ink!! Thats how simple it is to build your first pen-enabled application. </p> <p><span class="WBoxHeado">Power of the PEN!</span></p> <p align="center"><img border="0" src="../../img/intrototabletpcdev1.gif" width="300" height="300"><br> <b>Figure 1:</b> <i>Hello World in Ink (on Workstation)</i></p> <p align="left">The screen shot above shows Hello World!!! written in ink using a Mouse on a standard desktop machine. You will notice couple of things about this (besides my handwriting looking like a childs scribble).<br> 1) Its difficult to write text using mouse as input<br> 2) Mouse does not give me good writing control hence everything I write appears jagged.<br> &nbsp;</p> <p align="center"> <img border="0" src="../../img/intrototabletpcdev2.gif" width="300" height="300"><br> <b>Figure 2:</b> <i>Hello World in Ink (on Tablet PC)</i></p> <p align="left">If you look at the screen shot above (figure 2), this has been taken from my Tablet PC using a pen. If you compare the text on two screen shots you will see that not only does the ink from the pen look more readable but its smoother. This magic is done because of the following reasons:<br> <br> 1) While using a mouse, the rate at which packets are sent to the PC is very low like 30-35 samples per second. This is enough for general tasks, but not good enough for writing text. On the tablet pc the digitizer sends samples at the rate above 133 samples per second. Essentially sending the tablet enough information to make your handwriting appear life like. <br> <br> 2) The Tablet PC OS has been built in a way to accept this high frequency of packets on a high priority thread hence the ink flows as your pen moves rather than having some delay making it a natural writing experience. On top of this, in real time the Ink from the pen is smoothened and anti-aliased to give a natural feel. </p> <p align="left"><span class="wboxheado">Ink Ink Ink What is Ink?</span> <br> I have been referring to text written in the sample above as Ink. But you could very well open MS Paint (or any drawing tool for that matter) and write/draw similarly since Windows 3.0, would that also be considered as Ink? Whats so special about Ink?<br> <br> Ink on the Tablet PC platform, is a collection of strokes made by the users pen. It not only handles the visualization of strokes made by the pen but it is also a data type. Each stroke contains other valuable information which allows us to build rich applications that can recognize text, perform various actions based upon the sequence/type of strokes etc. <br> Also by virtue of being a data type you can now store ink (serialize the ink to a file/database), copy ink into other applications (like Word), perform analysis on it etc. <br> <br> <span class="wboxheado">And what is a stroke?</span><br> A stroke is the set of data captured in a single pen/mouse down, up, move sequence. It would consist of the set of points consisting of the stroke as well as other packet data. <br> <br> In the listing below I have enhanced the sample to show the count of strokes made on the <i>InkCollector</i>. So after you make stroke/strokes you can click on the <b>Count Strokes</b> button to give you the count of strokes made on the <i>InkCollector</i> object. </p> <table border="0" width="100%" class="code" cellspacing="0" cellpadding="0"> <tr> <td width="100%"> <pre> using System ; using System.Windows.Forms ; using Microsoft.Ink ; using System.Drawing ; namespace MasterCSharp.TabletPC.Samples { public class FirstApp : Form { private InkCollector inkCollect ; private Button countStrokes; public FirstApp() { <span class="cmt">// Create and add a new Button to the form</span> countStrokes = new Button(); countStrokes.Text = "Count Strokes" ; countStrokes.Size = new Size(90,25); countStrokes.Click += new EventHandler(countStrokes_Click); this.Controls.Add(countStrokes); inkCollect = new InkCollector(this); inkCollect.Enabled = true ; } public static void Main() { Application.Run( new FirstApp() ); } protected override void Dispose( bool disposing ) { if( disposing ) { if( inkCollect != null ) inkCollect.Dispose(); } base.Dispose( disposing ); } private void countStrokes_Click(object sender, EventArgs e) { <span class="cmt">// Display the count of strokes</span> MessageBox.Show( inkCollect.Ink.Strokes.Count.ToString() ); } } } </pre> </td> </tr> </table> <p> In the sample above, I use the <b>Count</b> property of the <b>Strokes</b> collection of the <b>Ink</b> object associated with the <i>InkCollector</i> to get the count of the strokes made. <br> Recompile the sample with the same switch given above and run it.<p align="center"> <img border="0" src="../../img/intrototabletpcdev3.gif" width="301" height="302"><br> <b>Figure 3:</b> <i>Stroke Count (on Workstation)</i><p align="left"> In the screen shot above the number 7 indicates that 7 strokes were used to write the word Hello. 3 for H and one each for e,l,l and o. <br> As you can see from the example above each stroke made is stored separately, this allows us to build interesting applications where we could process each of the strokes coming from the pen. <br> <br> <span class="wboxheado">Conclusion</span><br> Hopefully this article gave you a quick start on developing applications on the Tablet PC Platform. In future articles we will start to explore different aspects of the platform deeply.

Comments

Add Comment