Answers To Self-Review Exercises


[Page 646 ( continued )]

Answers To Self-Review Exercises

13.1

a) True. b) True. c) True. d) True. e) False. RadioButton s are used to represent a set of mutually exclusive options. f) False. A Label 's text cannot be edited by the user . g) True. h) False. Some mouse events use EventArgs , others use MouseEventArgs . i) True. j) True. k) False. A control's tool tip text is set using a ToolTip component that must be added to the application.

13.2

a) focus. b) container. c) event. d) signature. e) password. f) GroupBox , Panel . g) mouse clicks, mouse presses, mouse moves. h) Key . i) Shift , Ctrl , Alt . j) multicast.



[Page 646 ( continued )]

Exercises

13.3

Extend the program in Fig. 13.26 to include a CheckBox for every font-style option. [ Hint: Use logical exclusive OR ( ^ ) rather than testing for every bit explicitly.]

13.4

Create the GUI in Fig. 13.41 (you do not have to provide functionality).

Figure 13.41. Calculator GUI.


13.5

Create the GUI in Fig. 13.42 (you do not have to provide functionality).

Figure 13.42. Printer GUI.



[Page 647]
13.6

Write a temperature conversion program that converts from Fahrenheit to Celsius. The Fahrenheit temperature should be entered from the keyboard (via a TextBox ). A Label should be used to display the converted temperature. Use the following formula for the conversion:

Celsius = ( 5 / 9 ) x ( Fahrenheit 32 )

13.7

Extend the program of Fig. 13.38 to include options for changing the size and color of the lines drawn. Create a GUI similar to Fig. 13.43. The user should be able to draw on the application's Panel . To retrieve a Graphics object for drawing, call method panelName .CreateGraphics() , substituting in the name of your Panel .

Figure 13.43. Drawing Panel GUI.


13.8

Write a program that plays "guess the number" as follows : Your program chooses the number to be guessed by selecting an int at random in the range 11000. The program then displays the following text in a label:

I have a number between 1 and 1000--can you guess my number?
         Please enter your first guess.

A TextBox should be used to input the guess. As each guess is input, the background color should change to red or blue. Red indicates that the user is getting "warmer," blue that the user is getting "colder." A Label should display either " Too High " or " Too Low ," to help the user zero in on the correct answer. When the user guesses the correct answer, display " Correct! " in a message box, change the Form 's background color to green and disable the TextBox . Recall that a TextBox (like other controls) can be disabled by setting the control's Enabled property to false . Provide a Button that allows the user to play the game again. When the Button is clicked, generate a new random number, change the background to the default color and enable the TextBox .

13.9

Write an application that allows users to process orders for fuzzy dice. The application should calculate the total price of the order, including tax and shipping. TextBox es for inputting the order number, the customer name and the shipping address are provided. Initially, these fields contain text that describes their purpose. Provide CheckBox es for selecting the fuzzy-dice color and TextBox es for inputting the quantities of fuzzy dice to order. The application should update the total cost, tax and shipping when the user changes any one of the three Quantity fields' values. The application should also contain a Button that when clicked, returns all fields to their original values. Use 5% for the tax rate. Shipping charges are $1.50 for up to 20 pairs of dice. If more than 20 pairs of dice are ordered, shipping is free. All fields must be filled out at the top, and an item must be checked for the user to enter a quantity for that item.