Test Your Knowledge: Exercises

Exercise 18-1. Create a Windows application that displays the word “Hello” in a label, and has a button that changes the display to “Goodbye”.

Exercise 18-2. Modify the first exercise by dragging a timer (found in the Components section of the Toolbox) onto the form and having the timer change the message from “Hello” to “Goodbye” and back once per second. Change the button to turn this behavior on and off. Use the Microsoft Help files to figure out how to use the timer to accomplish this exercise.

Exercise 18-3. Create a Windows application that calculates sales tax for a given amount. The user can enter an amount in a text box, and then can enter a sales tax between 0 and 25%, in increments of 0.25%. When the user clicks the Submit button, the tax is calculated, and both the tax and the total are output in a label. The application should look something like Figure 18-9 when it runs.

This is your goal for Exercise 18-3.

Figure 18-9. This is your goal for Exercise 18-3.

The amount is entered in a Textbox control, but for the tax, you want to restrict the values the user can enter, so you should use a numericUpDown control—use the Help files or IntelliSense to examine the properties for that control and figure out how to use them to your advantage. There’s a Clear button that clears the “Amount” TextBox when clicked.

To output a double with two decimal places, use ToString("F"). The F applies ...

Get Learning C# 3.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.