Answers to Self-Review Exercises


[Page 71 ( continued )]

Answers to Self-Review Exercises

2.1

a) visual programming. b) solution. c) auto-hide. d) tool tip. e) Solution Explorer . f) expand. g) alphabetically , categorically. h) Text . i) Toolbox . j) Dynamic Help . k) TextAlign .

2.2

a) True. b) False. The pin icon toggles auto-hide. The X box closes a window. c) True. d) False. The Toolbox contains icons that represent controls. e) False. Forms have a title bar but Label s do not (although they do have Label text). f) False. Control properties can be modified using the Properties window. g) True. h) False. Visual C# files use the filename extension .cs . i) True.



[Page 71 ( continued )]

Exercises

2.3

Fill in the blanks in each of the following statements:

  1. When an ellipsis button is clicked, a(n) __________ is displayed.

  2. To save every file in a solution, select __________.

  3. Using __________ help immediately displays a relevant help article. It can be accessed using the __________ key.

  4. GUI is an acronym for __________.

2.4

State whether each of the following is true or false . If false , explain why.

  1. A control can be added to a form by double clicking its control icon in the Toolbox .

  2. The form, Label and PictureBox have identical properties.

  3. If your machine is connected to the Internet, you can browse the Internet from the Visual Studio 2005 IDE.

  4. Visual C# programmers usually create complex programs without writing any code.

  5. Sizing handles are visible during execution.

2.5

Some features that appear throughout Visual Studio perform similar actions in different contexts. Explain and give examples of how the plus and minus boxes, ellipsis buttons, down-arrow buttons and tool tips act in this manner. Why do you think the Visual Studio 2005 IDE was designed this way?

2.6

Fill in the blanks in each of the following statements:

  1. The __________ property specifies which image a PictureBox displays.

  2. The __________ menu contains commands for arranging and displaying windows .

  3. The __________ property determines a form's or control's background color .

2.7

Briefly describe each of the following terms:

  1. toolbar

  2. menu bar

  3. Toolbox

  4. control

  5. form

  6. solution

[ Note: In the following exercises, you are asked to create GUIs using controls that we have not yet discussed in this book. The exercises will give you practice with visual programming onlythe programs will not perform any actions. You will be placing controls from the Toolbox on a form to familiarize yourself with what each control looks like. We have provided step-by-step instructions for you. If you follow these, you should be able to replicate the screen images we provide.]


[Page 72]
2.8

(Notepad GUI) Create the GUI for the notepad as shown in Fig. 2.50.

  1. Manipulating the Form 's properties. Change the Text property of the Form to My Notepad .

  2. Adding a MenuStrip to the Form . After inserting the MenuStrip , add items by clicking the Type Here section, typing a menu name (e.g., File , Edit , View and About ), then pressing Enter .

  3. Adding a RichTextBox to the Form . Change the Size property to 267 , 220 or use the sizing handles to resize the RichTextBox to the correct size. Change the Text property to Enter Text Here . Finally, set the Location property to 13 , 34 .

Figure 2.50. Notepad GUI.


2.9

(Calendar and Appointments GUI) Create the GUI for the calendar and appointments as shown in Fig. 2.51.


  1. [Page 73]
  2. Manipulating the Form 's properties. Change the Text property of the Form to My Scheduler . Set the Form 's Size property to 332 , 470 .

  3. Adding Label s to the Form . Add two Label s to the Form . Set the Label s' AutoSize properties to False . Both should be of equal size ( 178 , 21 ) and should be centered in the Form horizontally, as shown. Set the Label 's Text properties to match the figure as shown, using 12-point font size. Also set the BackColor property to Yellow .

  4. Adding a MonthCalendar control to the Form . Add this control to the Form and center it horizontally in the appropriate place between the two Label s.

  5. Adding a RichTextBox control to the Form . Add a RichTextBox control to the Form and center it below the second Label . Resize the RichTextBox accordingly .

Figure 2.51. Calendar and Appointments GUI.
(This item is displayed on page 72 in the print version)


2.10

( Calculator GUI) Create the GUI for the calculator as shown in Fig. 2.52.

  1. Manipulating the Form 's properties. Change the Size property of the Form to 272 , 192 . Change the Text property of the Form to Calculator .

  2. Adding a TextBox to the Form . Set the TextBox 's Text property in the Properties window to . Change the Size property to 240 , 20 . Set the TextAlign property to Right ; this right aligns text displayed in the TextBox . Finally, set the TextBox 's Location property to 8 , 16 .

  3. Adding the first Panel to the Form . Panel controls are used to group other controls. Change the Panel 's BorderStyle property to Fixed3D to make the inside of the Panel appear recessed. Change the Size property to 88 , 108 . Finally, set the Location property to 8 , 48 . This Panel contains the calculator's numeric keys.

  4. Adding the second Panel to the Form . Change the Panel 's BorderStyle property to Fixed3D . Change the Size property to 72 , 108 . Finally, set the Location property to 112 , 48 . This Panel contains the calculator's operator keys.

  5. Adding the third (and last) Panel to the Form . Change the Panel 's BorderStyle property to Fixed3D . Change the Size property to 48 , 72 . Finally, set the Location property to 200, 48 . This Panel contains the calculator's C (clear) and C/A (clear all) keys.

  6. Adding Button s to the Form . There are 20 Button s on the calculator. Add a Button to the Panel by dragging and dropping it on the Panel . Change the Text property of each Button to the calculator key it represents. The value you enter in the Text property will appear on the face of the Button . Finally, resize the Button s, using their Size properties. The Button s labeled 09 , x , / , - , = and . should have a size of 24, 24 . The 00 and OFF Button s are sized 48 , 24 . The + Button is sized 24 , 64 . The C (clear) and C/A (clear all) Button s are sized 32 , 24 .

Figure 2.52. Calculator GUI.


2.11

(Alarm Clock GUI) Create the GUI for the alarm clock as shown in Fig. 2.53.

  1. Manipulating the Form 's properties. Change the Size property of the Form to 256 , 176 . Change the Form 's Text property to Alarm Clock .


    [Page 74]
  2. Adding Button s to the Form . Add six Button s to the Form . Change the Text property of each Button to the appropriate text. Change the Size properties of the Hour , Minute and Second Button s to 56 , 23 . The ON and OFF Button s are sized 40 , 23 . The Timer Button is sized 48 , 32 . Align the Button s as shown.

  3. Adding a Label to the Form . Add a Label to the Form . Change the Text property to Snooze and set the AutoSize property to False . Set its Size to 248 , 23 . Set the Label 's TextAlign property to MiddleCenter . Finally, to draw a border around the edge of the Snooze Label , change the BorderStyle property of the Snooze Label to FixedSingle .

  4. Adding a GroupBox to the Form . GroupBox es are like Panel s, except that GroupBox es can display a title. Change the Text property to AM/PM , and set the Size property to 72 , 72 . To place the GroupBox in the correct location on the Form , set the Location property to 104 , 38 .

  5. Adding AM/PM RadioButton s to the GroupBox . Change the Text property of one RadioButton to AM and the other to PM , then set the AutoSize property of each RadioButton to False . Then place the RadioButton s as shown by setting the Location of the AM RadioButton to 16 , 16 and that of the PM RadioButton to 16 , 40 . Set their Size properties to 48 , 24 .

  6. Adding the time Label to the Form . Add a Label to the Form and change its Text property to 00:00:00 . Change the BorderStyle property to Fixed3D and the BackColor to Black . Set the AutoSize property to False , then set the Size property to 64, 23 . Use the Font property to make the time bold. Change the ForeColor to Silver (located in the Web tab) to make the time stand out against the black background. Set TextAlign to MiddleCenter to center the text in the Label . Position the Label as shown.

Figure 2.53. Alarm clock GUI.


2.12

(Radio GUI) Create the GUI for the radio as shown in Fig. 2.54. [ Note: All colors used in this exercise are from the Web palette, and the image can be found in the examples folder for Chapter 2.]

  1. Manipulating the Form 's properties. Change the Form 's Text property to Radio and the Size to 576 , 240 . Set BackColor to PeachPuff .

  2. Adding the Pre-set Stations GroupBox and Button s. Set the GroupBox 's Size to 232, 64 , its Text to Pre-set Stations , its ForeColor to Black and its BackColor to RosyBrown . Change its Font to bold . Finally, set its Location to 24 , 16 . Add six Button s to the GroupBox . Set each BackColor to PeachPuff and each Size to 24 , 23 . Change the Button s' Text properties to 1 , 2 , 3 , 4 , 5 and 6 , respectively.

  3. Adding the Speakers GroupBox and CheckBox es. Set the GroupBox 's AutoSize property to False , then set its Size to 160, 72 , its Text to Speakers and its ForeColor to Black . Set its Location to 280 , 16 . Add two CheckBox es to the GroupBox . Set each CheckBox 's Size to 56 , 24 . Set the Text properties for the CheckBox es to Rear and Front .

  4. Adding the Power On/Off Button . Add a Button to the Form . Set its Text to Power On/Off , its BackColor to RosyBrown , its ForeColor to Black and its Size to 72 , 64 . Change its Font style to Bold .


    [Page 75]
  5. Adding the Volume Control GroupBox , the Mute CheckBox and the Volume trackBar . Add a GroupBox to the Form . Set its Text to Volume Control , its BackColor to RosyBrown , its ForeColor to Black and its Size to 200, 80 . Set its Font style to Bold . Add a CheckBox to the GroupBox . Set its Text to Mute , its AutoSize property to False and its Size to 56, 24 . Add a TRackBar to the GroupBox .

  6. Adding the Tuning GroupBox , the radio station Label and the AM/FM RadioButton s. Add a GroupBox to the Form . Set its Text to Tuning , its ForeColor to Black and its BackColor to RosyBrown . Set its Font style to Bold and its Size to 216, 80 . Add a Label to the GroupBox . Set its BackColor to PeachPuff , its ForeColor to Black , its BorderStyle to FixedSingle , its Font style to Bold , its TextAlign to MiddleCenter , its AutoSize to False and its Size to 56 , 23 . Set its Tex t to 92.9 . Place the Label as shown in the figure. Add two RadioButton s to the GroupBox . Change the BackColor to PeachPuff , set the AutoSize to False and change the Size to 40,24 . Set the Text of one to AM and the other's to FM .

  7. Adding the image. Add a PictureBox to the Form . Set its BackColor to TRansparent , its SizeMode to StretchImage and its Size to 66 , 85 . Set the Image property to MusicNote.gif (located in the examples folder for Chapter 2).

Figure 2.54. Radio GUI.