Wednesday, June 2, 2004
Four Lines of Code Goes Four Platforms
Posted by Andy Sjostrom in "DEVELOPER" @ 11:30 AM
My Mobile List for Pocket PC
Let’s take a look at this tutorial’s demonstration application: “My Mobile List”. We’ll begin our journey on the Pocket PC platform. As you can see in Figure 1, the user can enter text into the text box and add the text to a list box. The user can clear the entire list or clear it item-by-item.
Figure 1: First class user interface!
I wouldn’t say this application would qualify as the most feature rich application, but it does look nice! Or maybe not…! Let’s take a look at how to develop the application.
Follow these steps to get started:
1. Start Visual Studio .NET 2003.
2. Start a New project.
3. Choose Crossfire Application.
Figure 2: New Crossfire Application.
4. Choose the appropriate target platform. This time we will choose “Pocket PC/Windows Mobile”.
Figure 3: Choose target platform.
The development environment will now provide an empty form with the right height and width based on the chosen platform.
5. Change form’s Text property to “My Mobile List”.
6. Add the following controls to the form: one text box, two buttons and a list box.
Figure 4: Add text box, buttons and a list box.
6. Set the Name property of the:
a) text box to: txtInput
b) “Add text” button to: btnAdd
c) list box to: lstText
d) “Clear all” button to: btnClearAll
e) “Clear selected” button to: btnClearSelected
7. Double-click the “Add text” button. You are now taken to the place where all the action takes place! Add the following code to the button’s click event:
Me.txtInput.Text = ""[/code]
The figure following shows what the code should look like including the lines of code associated with the click events of the “Clear all” and “Clear selected” buttons.
Figure 5: Behind the Scenes.
We are now all set! That's it! In essence, our application requires only four lines of code. You can now test the application by simply clicking the “Start” button in the development environment. The application is loaded into an emulation environment that runs on your PC and can emulate all of the mentioned platforms. This means that you don’t necessarily have to have devices running all target platforms. However, if you intend to do more serious work you will eventually have to test your code on a real device. The following figure illustrates the demonstration application running in a real Pocket PC vs. running in the emulation environment.
Figure 6: The Real Thing vs. the Emulator.
We will now move the application to other platforms!