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.

Choosing a Target 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

  1. 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.

  2. Select the Show device choices before deploying a device project check box.

Creating the Application

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

  1. (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.

  2. 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.

  3. In the Templates pane, click Smart Device Project.

  4. (Visual C# only) In the Location box, verify where you want to store your project files.

  5. In the Name box, type DeviceSample, and then click OK.

  6. 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

  1. 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.

  2. Right-click the Button control, and then click Properties.

  3. In the Properties window, type Say Hello, and press ENTER to set the Text property.

To add event handling for the Button control

  1. Double-click the button on the form.

    The Code Editor opens with the cursor positioned in the event handler.

  2. Insert the following Visual Basic code:

    MessageBox.Show("Hello, World!")


    Insert the following C# code:

    MessageBox.Show("Hello, World!");

Building and Debugging the Application

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

  1. On the Debug menu, click Start (or Start Debugging).

  2. 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.

  3. When the application is running on the emulator, tap the button to ensure that "Hello, World!" appears.

See Also


General, Device Tools, Options Dialog Box

Visual Basic and Visual C# (How Do I in Smart Devices)