This article by Dr. Jayaram Krishnaswamy teaches how you may create a .NET Compact Framework (CF) 2.0 forms application. This can be used with Pocket PC 2003, or later devices. In the absence of a device being available for testing, the emulator is the next best thing. The application will be tested on one of the many emulators available in Visual Studio 2005. You may try other devices as well just by choosing the item in the Device Emulation Manager described in the article.
Creating a Device Application
File | New | Project will open the New Project window as shown. Expand the Visual Basic node and follow it up by expanding the Smart Device node as shown. There are three kinds of Smart Devices listed; Pocket PC 2003, Smartphone 2003 and Windows CE 5.0. For this article the Pocket PC 2003 is chosen.
When you select Pocket PC 2003 in the left pane, the right hand pane shows many templates available for Pocket PC 2003. You will be able to create the application for CF 1.0 as well as CF 2.0. In this interface you may choose to create the following types of applications:
- Device Application: CF2.0 Forms APP for Pocket PC 2003 or later
- Device Application(1.0: CF1.0 Forms APP for Pocket PC 2003 or later
- Console Application: CF 2.0 non-graphic application
- Console Application(1.0: CF 1.0 non-graphic application
- Control Library : CF 2.0 controls for Pocket PC
Class library can be used for creating dll's.
Change the name of the default project name to something different. Here it is changed to Pocket2. When you click OK after changing the name of the project, the program creates a MyProject folder and a Form1.vb file which you see under Solution Explorer. You may rename the file.
The interface functions very much like, as if you are creating a Windows Application. The difference is you will be displaying a small foot print device as shown in the next figure. Form1 is displayed in the design mode and a mainMenu1 item is added to the Control Tray.
When you click on the mainMenu1 in the tray you get a visible cue as to what you should do next as shown. The mainMenu1 shows up with Smart Tasks as shown.
Now click on the Edit Menu and this opens up the Type Here area where you can enter some text. Here "Test" has been entered. This will create a single menu item "Test".
This is a nice interface where you can build up menu items very easily as shown in the next figure. All you need to do is just type in the area indicated by "Type Here". In addition to this you may also use other common controls from the toolbox.
Placing Other Controls on the Form
Because of the compact nature of the device with a reduced foot print, the controls available are a subset of the controls that you find normally in a desktop application. Where as controls in desktop can take a variety of arguments, the compact controls work with limited set of arguments. The next figure shows the device related controls that are available.
Let us go ahead and drag and drop (or double click in the Toolbox), a DateTime Picker control and a textbox as shown in the next figure. Rearranging objects is a snap because Visual Studio 2005 has an excellent support for sizing and aligning objects. The grid lines automatically snap in place (notice the thin blue line tying the alignment of Textbox1 with the DataTimePicker control. The Form1 text was changed using the Form's property window to read "Testing a simple device".
Attaching an Event to Test the Controls
Let us make use of the click event of the TestTime sub menu item to read from the DataTimePicker control and display it in the Textbox. To begin with, let us make the Textbox's text to be empty. Using the code shown the next paragraph we can show the date we pick from the DataTimePicker to display in the textbox. You can get to the code page by clicking on the TestTime sub menu [MenuItem3] item in the design window.
Note Form1.vb is renamed as MyFirstMobile.vb
Testing the Device
Click on the Build menu item to display the drop-down menu and choose to build the project.
After the Build succeeds (you should see a build succeeded message at the bottom of the screen) click on Start Debugging (green arrow) by the side of the Debug menu item. This displays the Deploy Pocket2 window as shown. There are a number of Pocket PC devices shown with the highlighted as the default.
Accept the default emulator and click on the Deploy button. When the deployment succeeds you should see a message to that effect in the Output window (you may access this from the View menu item). You will also see the emulator skin as shown in the next figure.
Which changes into the following when the program gets loaded.
Now click on the DateTimePicker control, pick a date as shown in the next figure.
After picking the date click on the sub menu item of Test which is TestTime. This transfers the date information from the DateTimePicker and places it in the textbox after adding some text as shown. You may pick another date and test it again.
When you try to close the device by hitting the close button at the top of the window the following window gets displayed.
If you choose Yes, the device state gets saved and the next message gets displayed.
Although a Pocket PC emulator was chosen you could get all the accessible devices using the Device Emulator sub menu item from the Tools menu as shown.
When you click on the Device Emulation Manager... you will see all the available devices as shown.
Get acquainted with the Object Browser
The Object Browser is one place where you may find clues as to what is happening in your program, whether you are using the correct syntax, etc. Refer to this important resource as you develop your programs.
This article described a simple introductory application for mobile devices. The application deployment to a Pocket PC emulator was also described.
About the Author :
Jayaram Krishnaswamy studied at the Indian Institute of Science in Bangalore India and Madras University in India and taught at the Indian Institute of Technology in Madras. He went to Japan on a Japanese Ministry of Education Research scholarship to complete his PhD in Electrical Engineering from Nagoya University. He was a Post-Doctoral Fellow at Sydney University in Australia; a Government of India Senior Scientific Officer at the Indian Institute of Science in Bangalore and Indian Institute of Technology at Kanpur; a Visiting Scientist at the Eindhoven Institute of Technology in the Netherlands; a visiting Professor of Physics at the Federal University in Brazil; an Associate Research Scientist at a government laboratory in São Jose dos Campos in São Paulo, Brazil; a visiting scientist at the National Research Council in Ottawa, Canada before coming to USA in 1985. He has also taught and worked at the Colorado State University in Fort Collins and North Carolina State University in Raleigh, North Carolina. He worked with Northrop Grumman Corporation on a number of projects related to high energy electron accelerators and Free Electron Lasers. These projects were undertaken at the Brookhaven National Laboratory in Long Island and in the Physics Department at Princeton University. He has over 80 publications in refereed and non-refereed publications and 8 issued patents. He is fluent in Japanese and Portuguese and lives in Honolulu, Hawaii, USA.
He has been working in IT-related fields since 1997. He was once a Microsoft Certified Trainer in Networking and a Siebel Certified developer. He has worked with several IT related companies, such as the Butler International in their Siebel practice, with several IBM sub-contractors and smaller companies. Presently he is active in writing technical articles in the IT field to many online sites such as http://CodeProject.com, http://APSFree.com, http://DevShed.com, http://DevArticles.com, http://OfficeUsers.org, http://ASPAlliance.com, Egghead Café, http://SSWUG.org, Packt Article Network, http://databasedev.co.uk, http://cimaware.com, and many others. Between 2006 and 2010 he wrote more than 400 articles mostly related to database and web related technologies covering Microsoft, Oracle, Sybase, ColdFusion, Sun, and other vendor products.
He has written four books all published by Packt related to Microsoft Database and Application Development: SQL Server Integration Services Using Visual Studio 2005, Learning SQL Server Reporting Services 2008, Microsoft SQL Azure; Enterprise Application Development, and Microsoft Visual Studio Lightswitch Business Application Development. He regularly writes for his four blogs on Blogger; http://Hodentek.blogspot.com, http://HodentekHelp.blogspot.com, http://HodentekMobile.blogspot.com, and http://HodentekMSSS.blogspot.com. He received the 2011 Microsoft Community Contributor award.
Books From Packt