Your message has been sent.
This article has been saved to your account.
Go to my account
This article has been emailed to your Kindle.
Send this article
Complete the form below to send this article, Development of Windows Mobile Applications (Part 1), to a friend (or to yourself). We will never share your details (or your friend's) with anyone. For more information, read our Privacy Policy.
A Windows Mobile is a Smart Phone with Windows Operating System. Windows OS in Windows Mobiles is the Compact Edition (CE) of the desktop Windows OS. This article will introduce you to writing Windows Mobile Applications using Visual C# and Microsoft Visual Studio 2008. This article by Prashant Thakkar will address:
- Essential features of Microsoft Visual Studio 2008 IDE that help in writing Windows Mobile Application.
- Writing your first Windows Mobile "Hello World" application and a "Quote of the Day" Application that uses Internet
- Packaging, Deploying and running your Windows Mobile Applications
Windows OS for Windows Mobile is available in various versions, but for this article we will be using Windows Mobile 6. Windows Mobile 6 uses .NET Compact Framework v2 SP2, and has 3 different versions:
- Windows Mobile 6 Standard (phones without Touch Screen)
- Windows Mobile 6 Professional (with Phone functionality)
- Windows Mobile 6 Classic (without Phone functionality)
Windows Mobile 6.1 and Windows Mobile 6.5 are other 2 higher versions available with some additional features as compared to Windows Mobile 6. Windows Mobile 7 expected to be released in 2010 and is said to have major updates.
This article concentrates on development on Windows Mobile 6 Professional.
Software Prerequisite
This article will introduce you to the development for Windows Mobile 6 Professional, using Visual C#. Windows Mobile 6 has .NET Compact Framework v2 SP2 preinstalled. .NET Compact Framework is a Compact Edition of .NET Framework, and does not have all the features of the complete .NET Framework.
Following are the software required for development:
- Microsoft Visual Studio 2008
- Windows Mobile 6 Professional SDK Refresh (SDK contains emulator, used for testing, debugging. To download click here)
- ActiveSync (Used for Data Synchronizing between development machine and Windows Mobile, To download click here)
Without making any exception, we will follow the golden rule of learning by writing “Hello World” application.
Hello World
We will assume that you have installed all the prerequisite software mentioned above.
Launch Visual Studio 2008 and select Visual C# (if prompted). Create a new Project (File -> New) as shown below:

While creating a new Project, Visual Studio 2008 IDE provides an option to select an installed template, which will create Project with all the basic requirements/structure for development. For Windows Mobile, we will select option Smart Device and template Smart Device Project as shown below. You can also provide:
- Name: Name for Project. We will call it as MyFirstApp.
- Location: Location where this project will be created. Browse and set the desired location. We will use default location for now.
- Solution Name: Name for referring the Solution. Usually we keep it same as Project Name.
Since Windows Mobile 6 has .NET Compact Framework v2, it will select the .NET Framework 2.0 from the dropdown on the top right. Click OK.

Next step is to select the Target platform, .NET Compact Framework Version and Template. For our application we will select:
- Target platform: Windows Mobile 6 Professional SDK
- .NET Compact Framework Version: .NET Compact Framework Version 2.0.
- Template: Device Application

Project MyFirstApp is successfully created and IDE will open a Form as shown.

Let me introduce you to the various sections on screen.
- This is the main section called development section. All the coding and designing of the Form is done here.
- This section is called Toolbox and lists all the available components. If this section is not visible click View->Toolbox.
- This section is called Solution Explorer and shows all the forms, resources and properties. If this section is not visible click View->Solution Explorer.
- This section is Properties and displays all the properties for the component selected. If this section is not visible click View->Properties Window.

By default Form is named as Form1. Let us first change the Name of the form. To do so select the form and the properties related to form will be listed in properties window.

The entire properties list is in the form of Key Value pair. For changing Name of form, change value of property Name. For this example we will change it to HelloWorldForm. Now this form will be referred as HelloWorldForm throughout the application.
Changing form name doesn’t change form caption (title) it is still showing Form1. To change caption change the value of property name Text. For this example we will change the Text to Hello World.

Also the file representing this form in Solution Explorer will still be referred as Form1.cs, again you can either keep the name of the file as it is or can rename it. We will rename it to HelloWorld.cs.

Looking at the top of development section you will find HelloWorld.cs [Design], this represents design of the form. In order to write a code, you need to have a class representation of the designed form. To switch to class representation, right click on development section and select option View Code to view code written for the Form.

View Code will open a Source Code editor HelloWorld.cs as shown below.

To toggle back to design either you can select HelloWorld.cs [Design] from the tab above or again right click and select option View Designer.

In Source Code editor mode no properties of form are available; also no components are shown in the Toolbox.
Now we will toggle back to designer.

Now after getting familiar with IDE let us quickly move to our next step. We will now place a button on the form and on the click of that button will display a message. To place button on form, select Button from Toolbox and drag it on to the form.

By default button will be referred as button1, we can either change it or leave it as it is. For now we will change it and will provide a meaningful name btnShowMessage for reference.

Now this button will be referred as btnShowMessage. But label on button is still referred as button1. And you are right, to change label on the button change the value of the property Text.

For showing message on button click we need to register a click event on button. To register click event, double click on the button. Double clicking on button will automatically register click event on the button and will create an abstract method to handle the same. Also view will change from designer to code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyFirstApp
{
public partial class HelloWorldForm : Form
{
public HelloWorldForm()
{
InitializeComponent();
}
private void btnShowMessage_Click(object sender, EventArgs e)
{
}
}
}
As seen system creates a method btnShowMessage_Click with 2 parameters , one of type object and another one of type EventArgs.
We saw the method that is been created by system for handling the click event, now let us see how and where this method is register for handling click Event. Click
on the Properties window.

As seen method btnShowMessage_Click is registered for Click event on button. Apart from Click, button has various other events as shown above.
Method btnShowMessage_Click was auto generated and registered by double clicking the button in designer view. One can even write a method directly using Source Code editor, but need to make sure to have 2 parameters, object and EventArgs in method signature and should return void.
For example we will create a method as follows:
private void showMessage(object sender, EventArgs e)
{
}

To register newly created method showMessage on click Event. Click
on Properties windows and then click on the right of the Event for which you want to register this method. A dropdown of all the methods with signature as explained above will be listed. Select appropriate method.
Now let us come back to our application, we have done will most of it now just need to add the code to show message.
We will display message using MessageBox, which will popup on button click. For this we need to add following line to the method btnShowMessage_Click.
MessageBox.Show("Hello World");
After adding the above line to the method, entire source code looks as follows:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace MyFirstApp
{
public partial class HelloWorldForm : Form
{
public HelloWorldForm()
{
InitializeComponent();
}
private void btnShowMessage_Click(object sender, EventArgs e)
{
MessageBox.Show("Hello World");
}
}
}
Now we have done with basic coding, So next step is to compile and run this code.
We will run this code in Debug mode. To execute click
at the top bar. A popup as shown below will come up asking where to deploy. For now select option "Windows Mobile 6 Classic Emulator" and click Deploy.

Windows Mobile Emulator will come up with the default screen as shown in Figure 1. After successful deployment, we can see our HelloWorld Form as shown in Figure 2.

Now click on ShowMessage button and we can see the message that we have written on the popup as shown below.

Click ok on the top right corner of the MessageBox to close it.
So far we have covered the following:
- How to Create Project using Visual Studio 2008 for Windows Mobile 6.
- Developing Hello World application.
- Running the application on Emulator.
Now let us see how to deploy it on Windows Mobile Device. For deploying the application on device you need to have ActiveSync installed.
>> Continue Reading: Development of Windows Mobile Applications (Part 2)
If you have read this article you may be interested to view :
About the Author :
Prashant Thakkar is Currently working as Senior Software Engineer at Xoriant Solution, Mumbai. He has over five years of experience of working on Java and Window Mobile Development. He can be contacted by email at prashant.thakkar@xoriant.com. Prashant is also active on Twitter, you can follow him at "ppandhi".



Post new comment