Building the Form Application
I have a standard, simple application I build as my "hello world" application when I use a new IDE, platform, or programming language. This is a simple application that includes a button, a text box, and a label. Clicking the button copies the text from the text box and appends it to the label. While this is not a practical application, it contains the basics of building a standard forms-based application.
Start by changing some of the properties for your application. Click on the form to display the form properties. Change the name to MyMobileAppForm. Change the text to "My Mobile App".
Just as you would in a normal Windows form application, add a Label, TextBox, and Button to your form. For this lab, you can leave the default names for the textbox and label. Rename the button by changing the Text property to "Do It". Your form should now look something like Figure 4 (note that the entire IDE is not shown).
Figure 4: Your application form
Now that you've designed your form, you need to add the code. This is again done just as you would in a standard application. Double-click on the button to add code to its click event. You will be placed in the Form1.cs file in the button1_Click method. Add the code shown in bold to this method:
private void button1_Click(object sender, System.EventArgs e)
label1.Text = textBox1.Text + "\n" + label1.Text;
textBox1.Text = "";
You'll see that this code is pretty simple. The first line places the current text in the textbox to the beginning of the label. A new line is used to separate the new text.
The next line is added to clear out the text in the textbox. You should note that when you enter these lines, you will see that the Intellisense helps you. All of the Intellisense features are available for building mobile applications just as they are in your standard applications. This line simply clears the textbox.
Go ahead and compile your application your application by pressing F5 or by selecting Start from the Debug menu. Note that if you get any errors, you should make sure your code is entered correctly. Additionally, I found that Form1 in the Main method was not always renamed when the form property was renamed. As such, you may need to change it to MyMobileAppForm.
If you don't get errors, the form will compile and deploy. You will see a message in the Build window such as this:
------ Deploy started: Project: MyMobileApp,
Configuration: Debug Pocket PC ------
After a few seconds (or minutes, depending on your machine), a pop-up will be displayed as shown in Figure 5.
Figure 5: The Deploy dialog
This dialog allows you to select from the valid devices connected to your machine for deployment. If you have a device, you can install to it provided it is connected to the machine. If not, you will still have the Pocket PC 2002 Emulator that you can deploy onto.
Select the Emulator and click the Deploy button. Again, your system will chug and churn as the emulator is loaded along with your application. When the emulator firsts loads, it will look like a standard PocketPC display. You should continue to wait while your application is loaded. Once loaded, your emulator should look like Figure 6.
Figure 6: Your Mobile Application running!
As you can see, the emulator looks—and will operate—like a real PocketPC device. You can enter text into the text box and click the Do It button. As you will see, the text is added to the label. All should work as expected. Figure 7 shows the emulator with a few lines of text entered.
Figure 7: Entered text in the mobile app!
Go ahead and close the mobile emulator window. When you do this, you may be prompted to save the emulator state or to close it. If you save the state, when you rerun your application from Visual Studio .NET 2003, it will start up quicker.