This documentation is archived and is not being maintained.

Walkthrough: Creating Windows Forms Applications for a Device 

In this walkthrough, you build a simple Windows Forms application 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.


The dialog boxes and menu commands you see might differ from those described in Help depending on your active settings or edition. To change your settings, choose Import and Export Settings on the Tools menu. 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

  1. On the Tools menu, click Options, click Device Tools, and then click General. (If Device Tools is not visible, 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 a Windows Forms project, as well as adding controls and event handling, follows the same process for device projects as it does for desktop projects. The major 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 2005, click New Project.


    (Visual C#) On the File menu in Visual Studio 2005, point to New, and then click Project.

  2. Under Project Types in the New Project dialog box, expand Visual Basic or Visual C#, expand Smart Device, and then click Pocket PC 2003.

    If the language you want does not at first appear, expand Other Languages. This display is governed by your development settings.

  3. Under Templates, click Device Application.

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

  5. (Visual C# only) In the Location box, verify where you want to store your project files, 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 the Toolbox is not visible, click Toolbox on the View menu.

    If the Device Controls tab is not visible in the Toolbox, right-click the Toolbox, and click Show All.

  2. Right-click the Button control, and 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 insertion point 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!");

At this point, you encounter a difference from desktop projects. In a device project, you can typically choose from among several targets where 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.

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

If you plan to do additional walkthroughs or open other projects, you want to shut down the emulator completely and exit this solution.

To close the emulator and the solution

  1. On the File menu of the emulator, click Exit.

  2. In the Device Emulator message box, click No to the message Save State Before Exiting?

  3. On the Visual Studio Debug menu, click Stop Debugging.

  4. If a message appears stating that the connection has been lost, click OK.

  5. On the File menu, click Close Solution.