Walkthrough: Creating Windows Forms Applications for a Device
In this walkthrough, you build a simple Windows Forms application by using either Visual Basic or Visual C#, and then run the application on a Pocket PC emulator. This walkthrough demonstrates the main difference between desktop and device programming, namely, that you must target a device. In this walkthrough, the device is a built-in emulator of the Pocket PC 2003.
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Visual Studio Settings.
This walkthrough was written using Visual Basic Development Settings and Visual C# Development Settings.
This walkthrough consists of five main tasks:
Creating a device project that uses Windows Forms.
Adding a control to the form.
Adding event handling to the control.
Selecting a device on which to run the project.
Building and deploying the application to the device.
To ensure that you are prompted to select a device when you deploy your solution, complete the following procedure.
To prompt for device choices at deployment time
On the Tools menu, click Options, expand Device Tools, and then click General.
If you cannot see Device Tools, select Show all settings at the bottom of the Options dialog box.
Select the Show device choices before deploying a device project check box.
Creating a Windows Forms project, and adding controls and event handling, follows the same process for device projects as it does for desktop projects. The main difference you encounter is the smaller number of classes available in the .NET Compact Framework.
To create a device project that uses Windows Forms
(Visual Basic) On the File menu in Visual Studio, click New Project.
(Visual C#) On the File menu in Visual Studio, point to New, and then click Project.
In the Project Types pane, expand Visual Basic or Visual C#, and then click Smart Device.
If the language you want does not at first appear, expand Other Languages. This display is governed by your development settings.
In the Templates pane, click Smart Device Project.
(Visual C# only) In the Location box, verify where you want to store your project files.
In the Name box, type DeviceSample, and then click OK.
In the Add New Smart Device Project dialog box, select Pocket PC 2003 from the Target platform drop-down, select .NET Compact Framework Version 2.0 from the .NET Compact Framework version drop-down, click Device Application in the Templates pane, and then click OK.
A representation of a Pocket PC device appears in the Windows Forms Designer.
To add a control to the form
From the Toolbox, drag a Button control onto the form.
If you cannot see the Toolbox in the integrated development environment (IDE), click Toolbox on the View menu.
If you cannot see the Device Controls tab in the Toolbox, right-click the Toolbox, and click Show All.
Right-click the Button control, and then click Properties.
In the Properties window, type Say Hello, and press ENTER to set the Text property.
To add event handling for the Button control
At this point, you encounter a difference from desktop projects. In a device project, you can typically choose from among several targets on which the project is to run. In this walkthrough, you choose a Pocket PC emulator. If you have a supported physical device already in partnership with your development computer, you could also choose the physical device.
To build and test the application
On the Debug menu, click Start (or Start Debugging).
In the Deploy dialog box, select Pocket PC 2003 SE Emulator, and then click Deploy.
You can view progress in the Status bar. By default, the .NET Compact Framework is deployed to the device if it is not already present on the device.
When the application is running on the emulator, tap the button to ensure that "Hello, World!" appears.