Learning the .NET Framework: Project A Currency Changer
(Page 1 of 3 )
Have you ever wanted to use the .NET Framework to develop a simple program, such as a currency converter? This article will help you to do just that. It is taken from chapter three of the book
Programming the .NET Compact Framework, written by Wei-Meng Lee (O'Reilly, 2005; ISBN: 0596004338).
Project A: Currency Converter
This first project shows how to develop a simple currency converter using the .NET Compact Framework’s built-in controls. For simplicity, the sample application is limited to three currencies: U.S. Dollar, CNY (Chinese Yuan), and Singapore Dollar. This application downloads the currency exchange rates from a web service when the application is first used. The application stores the rates in an XML document for subsequent usage.
Populating the Form with Controls In Visual Studio .NET 2003, create a new Smart Device Application (File -> New -> Project, then select Visual Basic Projects -> Smart Device Application). Set the Pocket PC as the target device and select a project type of Windows Application. Your project should open with the default Form1. Before you can add any of the controls, you need to set up two tab forms.
The application in this project contains one TabControl control, which in turn contains two TabPage controls. The first tab page is called Conversion, while the second is called Set Rates. The TabPage control lets you spread the controls across two pages.
To set it up, drag the TabControl from the toolbox onto the form. To add the tab page to a TabControl control, select the TabControl, right-click on it, and select Add Tab (see Figure 3-1).
To change the label of the TabPage, click the tab, select the TabPage (the region just above the tab), right-click on it, and select Properties. Change the Text property of the TabPage to Conversion. Do the same for the second tab page, but set its text to Set Rates. You should enlarge the TabControl so that it fills the form.
You must add the controls listed in Table 3-1 to this form (see Figures 3-2 and 3-3 for the layout). You’ll also need to add an Options item to the default MainMenu1.

Figure 3-1. Add a new TabPage control
Table 3-1. Controls used in the currency converter
Control type | Conversion tab | Set Rates tab |
Label | lblResult | "Base Currency: US$", "Symbol", "Rate" |
TextBox | txtValue | txtRate |
ComboBox | ComboBox1, ComboBox2 | ComboBox3 |
Button | cmd0–cmd9, cmdPt, cmdEq, cmdBackSpace, cmdClear | cmdUpdate |
The first tab page (Conversion) contains two ComboBox controls for the user to select the currencies to convert. Once the currencies are selected, the user can click on the numbered Button controls to input the amount to convert. The BackSpace button deletes the last character entered, while the Clear button clears the entire line of digits, as displayed

Figure 2-3. Setting up the form (Conversion tab page)

Figure 3-3. Setting up the form (Set Rates tab page)
in the TextBox control. The ListBox control contains a list of previous conversions.
In the second tab page (Set Rates), the user can set the exchange rate for each currency using the ComboBox and TextBox controls.
Next: Populating the Menu >>
More .NET Articles
More By O'Reilly Media
|
This article is taken from chapter three of the book Programming the .NET Compact Framework, written by Wei-Meng Lee (O'Reilly, 2005; ISBN: 0596004338). Check it out at your favorite bookstore. Buy this book now.
|
|