Rotating the text display on a Pocket PC/Win CE device


Let us first try to understand why rotating a text/bitmap is difficult to achieve on a Pocket PC 2003/Win CE 4.2 device.

The Compact Framework supports only a subset of the graphical output features of the Desktop Framework. You can do all of the more commonly required text drawing operations such as selecting different fonts by name, in different sizes and styles, and also control the color of drawn text.But this is a small price to pay for the small memory footprint occupied by the Compact Framework.

The System.Drawing.Graphics namespace is commonly used for almost any forms in the desktop framework, hence it has got lots of facilities to draw any kind of image on to the device context. However this namespace in the smaller version of the framework or the compact framework as It is commonly called is having only a very few classes/functionalities.

However there are means to overcome these short comings by making use of the win32 functions readily available/provided to the compact world.

Let me take a real world solution and give you an insight into it.

Problem at hand:

A Route sales Representative of Company A carries out a order/ sales for one of his prominent client (say for Wal-Mart) and after delivering the goods to his client he comes with his Pocket PC to take a signature from him for the delivery made.

Diagram 1: Signature Capture

Well This paper doesn't talk about how do we capture the signature (I will give you a hint ...Capture the Mouse Down and Up events and store the points into an Points[].To serialize it/or make it persistent store these points into an xml file (To simplify the reading of these points) ...You may probably find this in my next article J

Let us come back to our main discussion .So how we achieve this. As I told you I want to demonstrate a real life example. We also know that the data that is being displayed in the device are all dynamic depending on the store number, the sales ticket number, date and the quantity of item ordered by the client.

So we have to dynamically fill the display by retrieving these data from the local DB (ASA Database as it is commonly known).

Ok so the bottom line is we cannot rotate the control so what do we do rotate the font instead.

We will basically be making use of Win 32 functions from coredll (the most commonly imported dll in any of the smart device application.

In this sample I have made use of CreateFont and DrawText functions of the coredll.

Steps to be followed:

  1. Create a smart device application.

  2. Add labels and the panel where the signature is to be done.

  3. In the paint event get the control names and the data (from the DB) and store it into an array list.

  4. Pass these 2 array list to a user defined function called RotateText
    ie.. RotateText(mControlNames,mControlValues);

  5. Create a handle of the font to be used.
    IntPtr hFont = FontCache.CreateFont ("Tahoma", 9, FontStyle.Regular, 900);
    Important observation is the last parameter used i.e. 900 which indicates 90 degrees.

  6. Perform this operation for each control having text.
    Rectangle r = new Rectangle (ctl.ClientRectangle.X + 10, ctl.ClientRectangle.Bottom - 10, ctl.ClientRectangle.Width, -ctl.ClientRectangle.Height);
    FontCache.DrawText (hDC, hFont, arrControlNames [0].ToString (), arrControlNames[0].ToString ().Length,
    ref r, Win32.DT_TOP, Color. Black, Color. White);
    The win 32 functions Drawtext and CreateFont will have to be defined.

Definition for Win 32 Functions: (Refer attached source code)

For the signature part I have made use of a signature control (derived from control class) which displays a .png file on the panel.

This user control plays an important role when the client signs on the png file. As explained earlier derive this form Control class and override the Mouse Up, Mouse down and the Mouse move events to capture the movement of the mouse (stylus) on device. Generate an xml file to make these points persistent.

Hope you have got a brief insight into how rotation of the text can be implemented on a smart device.


Similar Articles