One Community, One World
Beginning Developing Smart Device Applications with Dot NET Compact Framework Part 2
by Ahmed Waly  on Sep 7 2006 12:00AM
  PageViews 6360   |    Add to Fav   |     Send to Friend   |    Download Code

Learn how to develop a smart device application targeting Windows mobile using .NET compact framework 2.0 and what is the difference between Compact framework 1.0 and 2.0.

Resources Used:
Microsoft Visual Studio 2005
.NET Compact Framework 2.0
.NET Compact Framework 2.0 SP1
Microsoft ActiveSync 3.8 or later (optional)

.NET compact framework 2.0 was released with Microsoft Visual Studio 2005 in November 2005, and it can be used only with Visual Studio 2005, and can't be used with any previous versions. It contains a lot of new controls and classes that were added and don't exist in compact framework 1.0.

Plus it supports only devices that are running with Windows Mobile 2003 SE and later, and it doesn't support previous Windows Mobile versions, I consider it as a drawback, but who's using these old devices anyway! 

What's New?
.NET compact framework 2.0 came with a long list of new features, and enhancements that were missed in v1.0; although it didn't include other required features and controls.

Some of the new controls that did not exist in v1.0 are like:

  • DateTimePicker Control.
  • LinkLable Control.
  • WebBrowser Control.

And there are other enhancements to existing controls like:

  • ComboBox Control; support for the DropDownStyle property.
  • ListView Control; the EnsureVisible method is supported. 
  • TextBox Control; added BorderStyle & HideSelection properties and Undo method.

And a lot more, you can find a list of what's new in .NET compact framework 2.0 here:  

Let's Start…
Now, we are going to make a simple application show how to use the new DateTimePicker control. Start Visual Studio 2005 and select a New Project, from New Project window, choose “Pocket PC 2003 Device Application"which is a compact framework 2.0 application by default.

Figure 1: Creating new project 

First thing you will notice is the changes in the classes' structure. You will find in the Solution Explorer a new class called ”Program"which holds the Main Method and the Startup Form Name.

Figure 2: New classes in Solution Explorer

And when you view each form's code behind, you will notice also the disappear of the “Initialize Component"method, you will notice also the existence of two classes for each form, one called “Form.cs"which holds all the implementations and controls events and the logic, and the other called “Form.designer.cs"and holds all the Form's auto generated code for the controls …etc

Now, from the ToolBox add a DateTimePicker, label, Button, and a textbox controls to the form as in the figure

Figure 3: Adding the controls

You can edit in the DateTimePicker control properties, like changing the calendar font, display it in certain format, and assign a Min Date and/or Max Date…etc

In the DateTimePicker control events, select “ValueChanged"event and double click on it to go to the event's code, and insert the following:

private void dateTimePicker1_ValueChanged(object sender, EventArgs e) 
        //Putting the selected date value in the textbox 
        txt_Date.Text = dateTimePicker1.Value.ToLongDateString(); 

This will change the textbox value everytime the user changes the date in the DateTimePicker control.

Now in the Click event of the button add the following: 

Language= "C#" Title="ChangeButton_Click" >
private void ChangeButton_Click(object sender, EventArgs e) 
         //Changing the date of the DateTimePicker, which will fire the "ValueChanged" event and change the textbox value too. 
        dateTimePicker1.Value = new DateTime(2005, 11, 09, 12, 30, 0); 

When pressing the Change button, it will change the DateTimePicker selected date to the assigned date written in the Click event, which in its turn will change the textbox value too to the new date because of the firing of the ValueChanged event.

Now, run the application and select the desired emulator or device to deploy the application to, and test the application your self and what happens as in the following pictures.

In the following figure, I used the DateTimePicker control to change the date

Figure 4: Changing the Date value

Next, in the following figure, you can see that the textbox value is changed too with the changing of the DateTimePicker value.

Figure 5: Textbox value changed too

Next, in the following figure, I pressed the Change button, which changed in his turn the DateTimePicker control Date value to the hard coded date “9th November 2005"which by the way was the VS2005 launch date.

You can see that both DateTimePicker control and the textbox values are changed.

Figure 6: after pressing the Change Button

In Part 3 (Final Part), I will talk about targeting Windows Mobile 05 applications and its new APIs.

With the release of .NET Compact framework 2.0, many new things were added to help the developers to design and develop smart device applications faster and easier than before, the only missing thing was the older versions compatibility issue.