mobile databases, mobile forms, and mobile synchronization … where you need to work
Providing Pocket Access, Mobile Database, Windows CE Database, and Windows CE Development Solutions

Tip of the Month (October 2009)

Handling Screen Rotation

A Visual CE form is laid out assuming that the handheld display is in portrait mode (taller than it is wide) or landscape mode (wider than it is tall). On many devices, it is possible to switch from one mode to the other while a form is open. And, of course, you want your form to adapt to the change.

There is no way to build a single form that works in both modes and still makes use of all the available screen space. Visual CE will not automatically move and resize your controls around to fit a changed screen orientation. You can, however, build two forms over the same table and, when the screen rotates, switch from one form to the other.

So the first thing you should do is create two forms. Call one PORTRAIT.VCE and the other LANDSCAPE.VCE. The easiest way to do this is create PORTRAIT.VCE first. Then copy the .VCE file and rename the copy to LANDSCAPE.VCE. Then open LANDSCAPE.VCE and just move the controls around.

The next thing you should do is put in the macros to deal with the screen rotations in PORTRAIT.VCE:

  • Create a macro called TO_LANDSCAPE. This macro will have two steps:
      STEP 1: JUMP to LANDSCAPE.VCE
      STEP 2: STOP MACRO
  • Create a macro called STARTUP. This macro will have four steps:
      STEP 1: SKIP (Num: if @landscape = 1 then 0 else 2)
      STEP 2: RUN MACRO (Macro: TO_LANDSCAPE)
      STEP 3: STOP MACRO
      STEP 4: RETURN FROM MACRO
While in the macro editor, click the EVENTS button:
  • Set the ON ROTATE event to launch TO_LANDSCAPE.
  • Set the ON STARTUP event to launch STARTUP.
Click OK, close the macro editor, and save your form.

Then, do a similar thing in LANDSCAPE.VCE:

  • Create a macro called TO_PORTRAIT. This macro will have two steps:
      STEP 1: JUMP to PORTRAIT.VCE
      STEP 2: STOP MACRO
  • Create a macro called STARTUP. This macro will have four steps:
      STEP 1: SKIP (Num: if @landscape = 0 then 0 else 2)
      STEP 2: RUN MACRO (Macro: TO_PORTRAIT)
      STEP 3: STOP MACRO
      STEP 4: RETURN FROM MACRO
While in the macro editor, click the EVENTS button:
  • Set the ON ROTATE event to launch TO_PORTRAIT.
  • Set the ON STARTUP event to launch STARTUP.
Click OK, close the macro editor, and save your form.

When the form runs, it will first check the orientation of the screen. If the wrong form is running, it will launch the right one. And, while the form is open, if the screen rotates, the other form will be launched.


Previous Tips of the Month