26.3 Creating and Displaying Windows Forms

 <  Day Day Up  >  

You want to create a Windows-Forms “based Smart Device Application.


Technique

To create a Windows Form application that targets mobile devices, select the Windows Application project type from the Smart Device Application project template. When the project is created, the IDE opens the Windows Form designer, allowing you to drag and drop controls and create event handlers using the same methods you learned for desktop applications.

Although the same procedures and methods apply for using Windows Forms, we need to address a few differences. First, mobile devices by default do not use a mouse. There is no way to get the current location of a mouse unless the user presses the stylus down onto the screen. Your application should not depend on the current position of the mouse unless it's in response to a MouseDown event. Furthermore, because there is no mouse, there is no mouse cursor. You can, however, create a wait cursor by setting the static property Cursor.Current to Cursor.Wait , which displays an animating cursor in the middle of the screen.

Applications that run in the Pocket PC operating system are not supposed to exit when the user presses the close button. Instead, the operating system uses an algorithm that closes applications that are not in use after a certain period of time. You will not receive the Close or Closing events when the user clicks the close button in the top-right corner of the form. If you ever want to use the "Designed for Pocket PC" logo, then you must allow the operating system to close your form instead of forcing a close from a menu event handler, for instance.

However, you can still allow an application to close while supporting the logo requirements by using a dialog-based approach. Instead of displaying a close (X) button in the upper-right corner of the form, you show an OK button; clicking it causes the Close and Closing events to fire and subsequently close your application. To support this behavior, set the MinimizeBox property of the form to False .

Windows Forms generally runs using the entire screen because the screen real estate is small for mobile devices. Even if you decide to set the Width and Height properties for your form to a small value, the form still expands to fill up the entire screen not covered by the title bar or bottom toolbar. To place your controls for a Pocket PC application, set the Width of the form to 240 and the Height to 320 while working in the Windows Form designer.

Comments

As you work with Windows Forms in a Smart Device Application, you'll almost forget you're working on a mobile device, at least until you begin to test your code. The .NET Compact Framework was designed to mirror the full .NET Framework as closely as possible, and one of the design decisions was to allow as much Visual Studio .NET designer support as possible.

Because you will do a majority of your initial testing using the emulator, following are a few tips and tricks that might help you if you are new to mobile-device application programming. The first is the default binary location. Even though the IDE communicates with the emulator to allow you to debug or simply launch your application from the IDE, it's still good to know where the final binary is located within the emulator. The default location is the \Program Files\ ProjectName directory. The emulator contains a built-in application called File Explorer, which is the same application that ships with all Pocket PCs. To launch the File Explorer, click the Start button on the top of the toolbar and select the Programs menu item, which brings up a list of programs that are installed (of which File Explorer is one). You might find it easier to move that location to a more accessible area such as the Start menu itself. To do so, open your project property pages and select the Device property page from the Common Properties group . Next, change the Output File Folder to \Windows\Start Menu .

When you build your project, you need to deploy it to the emulator before running it. To do so, click on Build from the main menu and select the Deploy ProjectName menu item. If you are debugging, deployment occurs automatically. You will eventually run into the problem of not being able to deploy the application because of the Windows closing behavior described in the "Technique" portion of this recipe. Even though the form is gone, the application is still running in the background. There are two ways around this problem. The first is to click on the Start menu within the emulator and select the Settings tab. Next, click on the System tab and open the Memory control panel applet. You then see a tab that says Running Programs, which allows you to stop any applications that are currently running. The second option, which is easier and guarantees that you won't forget to manually stop the process, is to forgo the Pocket PC logo requirements during the implementation phase of your application. You can do so by creating a menu item, a button control, or simply an event handler for the Click event on the form. In any case, when you call the Close method, the application will exit.

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net