Friday, May 18, 2007

When building windows mobile forms,  you need to know where you are.   You need to know when to display, next buttons, indicate when no records are found and tightly control the user experience.     Controlling when things are displayed hidden etc.  can take a while to perfect and an age to debug.    The approach I take is as follows.

// Firstly I setup a enumeration, of what states a particular form can be in, for example -

private enum windowstates
{

undefined,
opening,
notfound,
foundmultiple,
foundone

}

// Next I store the current state our form is in and the previous state, to avoid any unnecessary repainting

private windowstates currentstate = windowstates.opening;
private windowstates previousstate = windowstates.undefined;

 

// Whenever I need to switch on and off different form elements, I set the state and call a button_handler()

private void something_happened()
{
currentstate=windowstates.foundmultiple;
button_handler()
}

 

// Finally, the button handler switches on and off the various form elements in one place

private void button_handler()
{

if (currentstate == previousstate) return;
previousstate = currentstate;


switch (currentstate)
{
case windowstates.opening:

// switch on and off form elements
// set focus on controls etc.
break;

case windowstates.notfound:
// switch on and off form elements
// set focus on controls etc.
break;

case windowstates.foundone:

// switch on and off form elements
// set focus on controls etc.

break;

}
}

This approach means that I only have to get the button handler routine correct once, and all forms are then extremely easy to maintain.    I know techniques like databinding also help with this but for simple and effective reliable form building this works a treat.

 

Technorati tags:
Friday, May 18, 2007 3:02:34 PM UTC  #    Comments [0]  | 

Theme design by Jelle Druyts

Pick a theme: