Simply C#An Application Driven Tutori

  O N T E N T S C

  Drawing Application

  1

  1 Introducing Computers, the Internet and C#

  2 Welcome Application

  4 Introducing the Visual Studio .NET IDE

  3 Welcome Application

  8 Introduction to Visual Programming

  4 Designing the Inventory Application

  25 Introducing TextBoxes and Buttons

  5 Completing the Inventory Application

  32 Introducing Programming

  6 Enhancing the Inventory Application

  51 Introducing Variables, Memory Concepts and Arithmetic

  7 Wage Calculator Application

  71 Introducing Algorithms, Pseudocode and Program Control

Dental Payment Application

  8

  94 Introducing CheckBoxes and Message Dialogs

  9 Car Payment Calculator Application 131

  Introducing the while Repetition Statement

  Class Average Application

  10 153

  Introducing the dowhile Repetition Statement

  11 Interest Calculator Application 175

  Introducing the for Repetition Statement

  12 Security Panel Application 197

  Introducing the switch Multiple-Selection Statement

  13 Enhancing the Wage Calculator Application 226

  Introducing Methods

  14 Shipping Time Application 248

  Using DateTimes and Timers

   i

  Brief Table of Contents i i

  15 Fund Raiser Application 267

  Introducing Scope and Pass-by-Reference

  16 Craps Game Application 285

  Introducing Random-Number Generation

  17 Flag Quiz Application 306

  Introducing One-Dimensional Arrays and ComboBoxes

  Student Grades Application

  18 330

  Introducing Two-Dimensional Arrays and RadioButtons

  Microwave Oven Application

  19 355

  Building Your Own Classes and Objects

  Shipping Hub Application

  20 395

  Introducing Collections, the foreach Statement and Access Keys

  21 “Cat and Mouse” Painter Application 427

  Introducing the Graphics Object and Mouse Events

  22 Typing Application 447

  Introducing Keyboard Events, Menus and Dialogs

  23 Screen Scraping Application 475

  Introducing string Processing

  24 Ticket Information Application 497

  Introducing Sequential-Access Files

  25 ATM Application 521

  Introducing Database Programming

  26 Check Writer Application 555

  Introducing Graphics and Printing

  Phone Book Application

  27 584

  Introducing Multimedia Using Microsoft Agent

  Bookstore Application: Web Applications

  28 611

  Introducing Internet Information Services

  Bookstore Application: Client Tier

  29 614

  Introducing Web Controls

  Bookstore Application: Information Tier

  30 621

  Examining the Database and Creating Database Components

  Bookstore Application: Middle Tier

  31 625

  Introducing Code-Behind Files

  32 Enhanced Car Payment Calculator Application 642

  Introducing Exception Handling

  1 T U T O R

  I A L

  1 Drawing Application Introducing Computers, the Internet and C#

  Solutions

  Tutorial 1 Drawing Application

  a) NCL

  c) ALU

  d) CD-ROM

  a) machine

  b) intermediate-level

  c) high-level

  d) assembly

  a) TCP

  b) IP

  c) OOP

  d) FCL

  a) object-oriented

  b) centralized

  c) procedural

  d) HTML

  b) WCL

  a) TCP

  c) BASIC

  e) A C# program

  d) A word-processor program

  c) Input unit

  b) Compiler

  a) CPU

  d) Visual Basic

  b) C++

  c) FCL

  a) C#

  d) bandwidth

  c) traffic

  b) secondary storage

  a) networking

  d) PPCM

  b) RAM

  d) controls

  2 Instructor’s Manual Exercise Solutions

  1.6 Which protocol is primarily intended to create a “network of networks?”

  a. 1.3)

  b. 1.2)

  1.10 Which of these programming languages was specifically created for .NET? Answers: 1.1)

  1.9 The information-carrying capacity of communications lines is called .

  1.8 .NET’s collection of prepackaged classes and methods is called the .

  1.7 A major benefit of programming is that it produces software that is more understandable and better organized than software produced with previously used techniques.

  1.5 C# is an example of a(n) language, in which single program statements accomplish more substantial tasks.

  b. 1.5)

  1.4 is an example of primary memory.

  RadioButton s are examples of .

  Button s and

  1.3 TextBox es,

  1.2 Microsoft’s initiative integrates the Internet and the Web into software development.

  Tutorial 1 MULTIPLE-CHOICE QUESTIONS 1.1 The HyperText Markup Language was developed .

  d. 1.4)

  c. 1.6)

  c) IDEs

  d) as a replacement for the Internet

  b) high-level languages

  a) platforms

  d) W3C

  c) Windows

  b) BASIC

  a) .NET

  c) before the Internet

  b. 1.7)

  b) at CERN by Tim Berners-Lee

  a) by ARPA

  EXERCISES

  d. 1.10) a.

  c. 1.9)

  a. 1.8)

1.11 Categorize each of the following items as either hardware or software:

  

Introducing Computers, the Internet and C# Solutions Tutorial 1

  3 Answers: a) hardware. b) software. c) hardware. d) software. e) software.

1.12 Translator programs, such as assemblers and compilers, convert programs from one lan-

  guage (referred to as the source language) to another language (referred to as the target lan- guage). Determine which of the following statements are true and which are false: a) A compiler translates high-level-language programs into target-language programs.

  b) An assembler translates source-language programs into machine-language programs.

  c) A compiler translates source-language programs into target-language programs.

  d) Machine languages are generally machine independent.

  e) A machine-language program requires translation before it can be run on a computer.

  Answers:

  a) True. b) True. c) True. d) False. Machine languages are generally machine dependent. e) False. A machine language program is native to that specific machine and can be run without translation.

1.13 Computers can be thought of as being divided into six units.

  a) Which unit can be thought of as “the boss” of the other units?

  b) Which unit is the high-capacity “warehouse” that retains information even when the computer is powered off? c) Which unit might determine whether two items stored in memory are identical?

  d) Which unit obtains information from devices like the keyboard and mouse? Answers: a) CPU. b) Secondary storage unit. c) ALU. d) Input unit.

1.14 Expand each of the following acronyms:

  a) W3C

  b) TCP/IP

  c) OOP

  d) FCL

  e) HTML Answers:

  a) World Wide Web Consortium. b) Transmission Control Protocol/Internet Pro- tocol. c) Object-oriented programming. d) Framework Class Library. e) HyperText Markup Language.

  1.15 What are the advantages to using object-oriented programming techniques? Answer: Programs that use object-oriented programming techniques are easier to under- stand, correct and modify. The key advantage with using object-oriented programming is that it tends to produce software that is more understandable because it is better organized and has fewer maintenance requirements than software produced with earlier methodologies.

  OOP helps the programmer build applications faster by reusing existing software compo- nents. OOP also helps programmers create new software components that can be reused on future software-development projects.

  T U T O R

  I A L

2 Welcome Application

  ® Introducing the Visual Studio .NET IDE

  Solutions

  4

  Tutorial 2 Welcome Application

  a) the component object box

  c) pinned command

  d) minimize command

  a) drop-down list

  b) menu

  c) tool tip

  d) down arrow

  a) help documentation

  b) a toolbar

  c) windows for accessing project files d) All of the above.

  a) Solution Explorer window

  b) Properties window

  c) Start Page d) Toolbox link

  b) a Solution Explorer

  a) component-selection feature

  c) menus

  d) a menu bar

  a) component

  b) Form

  c) icon

  d) property

  a) Web View

  b) Excel

  c) a Web tab

  d) Internet Explorer

  a) toolbars

  b) icons

  b) Auto Hide feature

  d) Toolbox

  5 Instructor’s Manual Exercise Solutions

  2.11 For Web browsing, Visual Studio .NET includes .

  Tutorial 2 MULTIPLE-CHOICE QUESTIONS

  2.1 The integrated development environment (IDE) is used for creating applica-

tions written in .NET programming languages such as C#.

  2.2 The .cs filename extension indicates a .

  2.3 The pictures on toolbar Button s are called .

  2.4 The allows programmers to modify controls visually, without writing code.

  2.5 The hides the Toolbox when the mouse pointer is moved outside the Tool- Box

  ’s area.

  2.6 A appears when the mouse pointer is positioned over an IDE toolbar icon for a few seconds.

  

2.7 The Visual Studio .NET IDE provides .

  2.8 The contains a list of helpful links, such as Get Started and Online Commu- nity.

  2.9 The Properties window contains .

  2.10 A can be enhanced by adding reusable controls such as Button s.

  2.12 An application’s GUI can include .

  c) menu bar

  a) Solution Explorer b) Gates

  c) Visual Studio .NET

  d) Microsoft

  a) C# file

  b) dynamic help file

  c) help file

  d) cool solution file

  a) prototypes

  b) icons

  c) tool tips

  d) tabs

  a) Properties window

  b) Solution Explorer

  c) menus d) All of the above.

  

Introducing the Visual Studio® .NET IDE Solutions Tutorial 2

  6

2.13 The does not contain a pin icon.

  a) Dynamic Help window

  b) Solution Explorer window

  c) Toolbox window

  d) active tab

  2.14 When clicked, in the Solution Explorer window will expand nodes and will collapse nodes.

  a) minus boxes; plus boxes

  b) plus boxes; minus boxes

  c) up arrows; down arrows

  d) left arrows; right arrows Form 2.15 specify attributes such as size and position.

  a) nodes

  b) inputs

  c) properties

  d) title bars Answers:

  2.1) c . 2.2) a . 2.3) b . 2.4) a . 2.5) b. 2.6) c . 2.7) d . 2.8) c . 2.9) a . 2.10) b . 2.11) d . 2.12) d . 2.13) d . 2.14) b . 2.15) c .

  (

  2.16 Closing and Opening the Start Page) In this exercise, you will learn how to close and EXERCISES reopen the Start Page (Fig. 2.30). To accomplish this task, perform the following steps:

  Close box Figure 2.30 Showing the Start Page.

  a) Close Visual Studio .NET if it is open by clicking its close box.

  b) Start Visual Studio .NET.

  c) Close the Start Page by clicking its close box (Fig. 2.30).

  d) Select Help > Show Start Page to display the Start Page.

  (

2.17 Enabling Auto Hide for the Solution Explorer Window) In this exercise, you will

  learn how to use the Solution Explorer window’s Auto Hide feature (Fig. 2.31) by perform- ing the following steps: Vertical pin icon Figure 2.31 Enabling Auto Hide.

  a) Open the Start Page.

  Button

  b) In the Projects tab (displayed by default), click the Open Project to display the Open Project dialog. You can skip to Step e if the Welcome application is already open.

  c) In the Open Project dialog, navigate to C:\SimplyCSP\Welcome , and click Open.

  Welcome.sln d) In the Open Project dialog, select , and click Open.

  e) Position the mouse pointer on the vertical pin icon in the Solution Explorer win- dow’s title bar. After a few seconds, a tool tip appears displaying the words Auto Hide.

  Tutorial 2 Welcome Application

  7 f) Click the vertical pin icon. This action causes a Solution Explorer tab to appear on the right side of the IDE. The vertical pin icon changes to a horizontal pin icon

  (Fig. 2.32). Auto Hide has now been enabled for the Solution Explorer window.

Figure 2.32 Solution Explorer window with Auto Hide enabled.

  g) Position the mouse pointer outside the Solution Explorer window to hide the win- dow.

  h) Position the mouse pointer on the Solution Explorer tab to view the Solution Explorer window.

  2.18 (S orting Properties Alphabetically in the Properties Window) In this exercise, you will learn how to sort the Properties window’s properties alphabetically (Fig. 2.33) by per- forming the following steps:

Figure 2.33 Sorting properties alphabetically.

  a) Open the Welcome application by performing Steps a–d of Exercise 2.17. If the Wel- come application is already open, you can skip this step.

  b) Locate the Properties window. If it is not visible, select View > Properties Window to display the Properties window.

  c) To sort properties alphabetically, click the Properties window’s alphabetic icon. The properties will display in alphabetic order.

  Horizontal pin icon Solution Explorer tab Alphabetic icon

  T U T O R

  I A L

  3 Welcome Application Introduction to Visual Programming

  Solutions

  8

  Tutorial 3 Welcome Application

  c) System.Form.Font

  a) Font Property dialog

  b) New Font dialog

  c) Font Settings dialog

  d) Font dialog

  a) Picture

  b) ImageName

  c) Image

  d) PictureName

  a) Custom b) Web

  c) System d) User

  a) System.Windows.Forms

  b) System.Form.Form

  d) System.Form.Control

  a) Save > Solution > Save Files b) File > Save

  a) Caption

  b) Data

  c) Text

  d) Name

  a) start

  b) run

  c) execute

  d) design

  a) Lock Controls b) Anchor Controls

  c) Lock d) Bind Controls

  a) picture elements

  b) controls in the Toolbox

  c) a set of fonts

  c) File > Save All d) File > Save As…

  d) Color

  9 Instructor’s Manual Exercise Solutions

  3.10 Pixels are . Answers:

  Tutorial 3 MULTIPLE-CHOICE QUESTIONS

  3.1 The property determines the Form ’s background color.

  3.2 To save all the solution’s files, select .

  3.3 When the ellipsis

Button

to the right of the Font property value is clicked, the is displayed.

  3.4 PictureBox property contains a preview of the image displayed in the

  PictureBox .

  3.5 The tab allows you to create your own color.

  3.6 The PictureBox class belongs to the namespace.

  3.7 A Label control displays the text specified by the property.

  3.8 In mode, the application is running (executing).

  3.9 The command prevents programmers from accidentally altering the size and location of the

  Form ’s controls.

  3.1)

  c) RGB

  a. 3.2)

  c. 3.3)

  d. 3.4)

  c. 3.5)

  a. 3.6)

  a. 3.7)

  c. 3.8)

  b. 3.9)

  a. 3.10) a.

  EXERCISES For Exercises 3.11–3.16, you are asked to create the GUI shown in each exercise. You will use the visual programming techniques presented in this tutorial to create a vari- ety of GUIs. Because you are creating only GUIs, your applications will not be fully operational. For example, the Calculator GUI in Exercise 3.11 will not behave like a calculator when its

  Button s are clicked. You will learn how to make your applications fully operational in later tutorials. Create each application as a separate project.

  a) BackColor

  b) BackgroundColor

  d) a set of colors on the Web tab Introduction to Visual Programming Solutions Tutorial 3

  10 3.11 (Calculator GUI) Create the GUI for the calculator shown in Fig. 3.33.

  Subtraction Button TextBox Panel (contains 2 Buttons) Panel (contains 11 Buttons for the numeric keys)

  Panel (contains 6 Buttons) Button

Decimal point Button

Figure 3.33 Calculator GUI.

  a) Creating a new project. Open Visual Studio .NET. Create a new project in your C:\SimplyCSP directory named Calculator .

  b) Renaming the Form file. Name the Form file Calculator.cs . Double click the file

name to open the Form in design view.

  c) Manipulating the Form ’s properties. Change the Size property of the Form to 272 , 192 . Change the Text property of the Form to Calculator . Change the Font prop- erty to Tahoma.

  d) Adding a TextBox to the Form . Add a TextBox control by double clicking it in the Toolbox. A TextBox control is used to enter input into applications. Set the Text- Box ’s Text property in the Properties window to . Change the Size property to 240 ,

  21 . Set the TextAlign property to Right ; this right aligns text displayed in the TextBox . Finally, set the TextBox ’s Location property to 8 , 16 .

  e) Adding the first Panel to the Form . Panel controls are used to group other controls.

  Double click the Panel icon ( ) in the Toolbox to add a Panel to the Form . Change the Panel ’s BorderStyle property to Fixed3D to make the inside of the Panel appear recessed. Change the Size property to 88 , 112 . Finally, set the Location property to 8 , 48 . This Panel contains the calculator’s numeric keys.

  Tutorial 3 Welcome Application

  11 f) Adding the second Panel to the Form . Click the Form . Double click the Panel icon in the Toolbox to add another Panel to the Form . Change the Panel ’s BorderStyle property to Fixed3D . Change the Size property to 72 , 112 . Finally, set the Location property to 112 ,

  48 . This Panel contains the calculator’s operator keys.

  g) Adding the third (and last) Panel Form Click the Form . Double click the to the .

  Panel icon in the Toolbox to add another 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.

  h) Adding Button s to the Form . There are 20 Button s on the calculator. To add a But- ton to a Panel , double click the Button control ( ) in the Toolbox.

  Then add the 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. Each Button labeled 0–9 , x , / , , = and . - should have a size of 24, 24 . The 00 and OFF Button s have size 48 , 24 . The + But- ton is sized 24 , 64 . The C (clear) and C/A (clear all) Button s are sized 32 , 24 .

i) Saving the project. Select File > Save All to save your changes.

  j) Closing the IDE. Close Visual Studio .NET by clicking its close box.

3.12 Create the GUI for the alarm clock in Fig. 3.34.

  (Alarm Clock GUI) Buttons RadioButton

  GroupBox

Label

Alarm Clock GUI.

  Figure 3.34 Introduction to Visual Programming Solutions Tutorial 3

  12 a) Creating a new project. Open Visual Studio .NET. Create a new project in your

  

C:\SimplyCSP AlarmClock

directory named .

  Form Form AlarmClock.cs

  b) Renaming the file. Name the file . Double click the file Form name to open the in design view.

  Form Size Form 256

  c) Manipulating the ’s properties. Change the property of the to , 176 Text Form Alarm Clock Font

  . Change the property of the to . Change the prop- erty to Tahoma.

  d) Adding Button Form Add six Button s to the Form . Change the Text prop-

s to the .

erty 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 get size 40 , 23 .

  The Timer Button gets size 48 , 32. Align the Button s as shown in Fig. 3.34.

  e) Adding a Label to the Form . Add a Label to the Form . Change the Text property to Snooze. Set its Size to 248 , 23 . Set the Label ’s TextAlign property to Middle- Center . Finally, to draw a border around the edge of the Snooze Label , change the

  BorderStyle property of the Snooze Label to FixedSingle .

  f) Adding a GroupBox to the Form . GroupBox es are like Panel s, except that Group- Box es can display a title. To add a GroupBox to the Form , double click the GroupBox control ( ) in the Toolbox. 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 .

  RadioButton GroupBox RadioButton Form

  g) Adding AM/PM s to the . Add two s to the

RadioButton

by dragging the control ( ) in the Toolbox and dropping it

  Tutorial 3 Welcome Application

  13 GroupBox Text RadioButton AM onto the twice. Change the property of one to and

  PM RadioButton the other to . Then place the s as shown in Fig. 3.34 by setting the Location RadioButton

  16

  16 RadioButton

  16 of the AM to , and that of the PM to ,

40 Size

  48

  24 . Set their properties to , .

  Label Form Label Form Text

  h) Adding the time to the . Add a to the and change its property to 00:00:00 . Change the BorderStyle property to Fixed3D and the Back- Color to Black . 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 in Fig. 3.34.

i) Saving the project. Select File > Save All to save your changes.

  j) Closing the IDE. Close Visual Studio .NET by clicking its close box.

3.13 Create the GUI for the microwave oven shown in Fig. 3.35.

  (Microwave Oven GUI) Panel Panel (door) Label Buttons

  Microwave Oven GUI.

  Figure 3.35

  a) Creating a new project. Open Visual Studio .NET. Create a new project in your C:\SimplyCSP Microwave

directory named .

  Form Form Microwave.cs

  b) Renaming the file. Name the file . Double click the file Form name to open the in design view.

  Form Size Form 552

  c) Manipulating the ’s properties. Change the property of the to , 288 Text Form Microwave Oven Font

  . Change the property of the to . Change the property to Tahoma. Introduction to Visual Programming Solutions Tutorial 3

  14 Panel Form

  d) Adding the microwave oven door. Add a to the by double clicking the Panel Panel BackColor

  ( ) in the Toolbox. Select the and change the Silver property to (located in the Web tab) in the Properties window. Then change

  Size 328 224 BorderStyle FixedSingle the to , . Next, change the property to .

  e) Adding another Panel Add another Panel and change its Size to 152 , 224 and its

.

  BorderStyle to FixedSingle . Place the Panel to the right of the door Panel as shown in Fig. 3.35.

  f) Adding the microwave oven clock. Add a Label to the right Panel by clicking the Label in the Toolbox once, then clicking once inside the right Panel . Change the Label ’s Text to 12:00 , BorderStyle to FixedSingle and Size to 120 ,

  48 . Change TextAlign to MiddleCenter . Place the clock as shown in Fig. 3.35.

  Tutorial 3 Welcome Application

  15 g) Adding a keypad to the microwave oven. Place a Button in the right Panel by click- ing the Button control in the Toolbox once, then clicking inside the Panel . Change the Text to 1 and the Size to 24 , 24 . Repeat this process for nine more Button s, changing the Text property in each to the next number in the keypad. Then add the Start and Clear Button s, each of Size 64 , 24 . Do not forget to set the Text proper- ties for each of these Button s. Finally, arrange the Button s as shown in Fig. 3.35. The

1 Button is located at 40 , 80 and the Start Button is located at 8 , 192 .

h) Saving the project. Select File > Save All to save your changes.

i) Closing the IDE. Close Visual Studio .NET by clicking its close box.

  3.14 (Cell Phone GUI) Create the GUI for the cell phone shown in Fig. 3.36.

  Label Panel Figure 3.36 Cell Phone GUI. Introduction to Visual Programming Solutions Tutorial 3

  16 a) Creating a new project. Open Visual Studio .NET. Create a new project in your

  C:\SimplyCSP Phone directory named .

  Form Form Phone.cs

  b) Renaming the file. Name the file . Double click the file name to Form open the in design view.

  Form Form Text Phone

  c) Manipulating the ’s properties. Change the ’s property to and Size 160 488 Font the to , . Change the property to Tahoma.

  d) Adding the display Label . Add a Label to the Form . Change its BackColor to Aqua (in the Web tab palette), the Text to Welcome to Deitel Mobile Phone! and the Size to 136 , 184 . Change the TextAlign property to MiddleCenter . Then place the Label as shown in Fig. 3.36.

  Panel Panel Form BorderStyle

  e) Adding the keypad . Add a to the . Change its prop- FixedSingle Size 104 136

erty to and its to , .

  Tutorial 3 Welcome Application

  17 f) Adding the keypad Button s. Add the keypad Button s to the Form (12 Button s in

all). Each Button on the number pad should be of Size

  24 , 24 and should be placed in the Panel . Change the Text property of each Button such that numbers 0–9 , the pound ( # ) and the star ( ) keys are represented. Then add the final two Button s such * that the Text property for one is Talk and the other is End . Change the Size of each Button to 24 , 80 , and notice how the small Size causes the Text to align vertically.

  Change the Font size of these two Button s to 12 .

  g) Placing the controls. Arrange all the controls so that your GUI looks like Fig. 3.36.

  h) Saving the project. Select File > Save All to save your changes.

i) Closing the IDE. Close Visual Studio .NET by clicking its close box.

3.15 Create the GUI for the vending machine in Fig. 3.37.

  (Vending Machine GUI) Introduction to Visual Programming Solutions Tutorial 3

  18 Label PictureBoxes

  GroupBox Panel

Vending Machine GUI.

  Figure 3.37

  a) Creating a new project. Open Visual Studio .NET. Create a new project in your C:\SimplyCSP VendingMachine directory named .

  b) Renaming the Form file. Name the Form file VendingMachine.cs . Double click the file name to open the Form in design view.

  c) Manipulating the Form ’s properties. Set the Text property of the Form to Vending Machine and the Size to 560 , 488 . Change the Font property to Tahoma.

  d) Adding the food selection Panel Add a Panel to the Form , and change its Size to .

  312 , 344 and BorderStyle to Fixed3D . Add a PictureBox to the Panel , and change its Size to 50 , 50 . Then set the Image property by clicking the ellipsis Button and choosing a file from the C:\Examples\Tutorial03\ExerciseImages\VendingMa- chine directory. Repeat this process for 11 more PictureBox es.

  Tutorial 3 Welcome Application

  19 e) Adding Label Add a Label under each PictureBox .

s for each vending item.

  Change the Text property of the Label to A1 , the TextAlign property to TopCenter and the Size to 56 , 16 . Place the Label so that it is located as in Fig. 3.37. Repeat this process for A2 through C4 (11 Label s).

  f) Creating the vending machine door (as a Button ). Add a Button to the Form by dragging the Button control in the Toolbox and dropping it below the Panel .

  Change the Button ’s Text property to PUSH , its Font Size to 36 and its Size to 312 , 56 . Then place the Button on the Form as shown in Fig. 3.37.

  20 Introduction to Visual Programming Solutions

  Tutorial 3 g) Adding the selection display Label .

  Add a Label to the Form , and change the Text property to B2 , BorderStyle to FixedSingle , Font Size to 36 , TextAlign to Mid- dleCenter and Size to 160 ,

  72 .

  h) Grouping the input Button s. Add a GroupBox below the Label , and change the Text property to Please make selection and the Size to 160 , 136 .

  Tutorial 3 Welcome Application

  21

i) Adding the input Button Finally, add Button s to the GroupBox . For the seven But- s.

  ton s, change the Size property to 24 , 24 . Then change the Text property of the But- ton s such that each Button has one of the values A , B , C , 1 , 2 , 3 or 4 , as shown in

  Fig. 3.37. When you are done, move the controls on the Form so that they are aligned as shown in Fig. 3.37. j) Saving the project. Select File > Save All to save your changes. k) Closing the IDE. Close Visual Studio .NET by clicking its close box.

  ▲

  Programming Challenge

  3.16 (Radio GUI) Create the GUI for the radio in Fig. 3.38. [Note: All colors used in this exercises are from the Web palette.] Introduction to Visual Programming Solutions Tutorial 3

  22 GroupBox CheckBoxes Button

  TrackBar GroupBoxes RadioButtons PictureBox Radio GUI.

  Figure 3.38 In this exercise, you will create this GUI on your own. Feel free to experiment

  PictureBox with different control properties. For the image in the , use the file

  MusicNote.gif C:\Examples\Tutorial03\ExerciseImages\Radio ( ) found in the directory.

  a) Creating a new project. Open Visual Studio .NET. Create a new project in your C:\SimplyCSP Radio directory named .

  Form Form Radio.cs

  b) Renaming the file. Name the file . Double click the file name to Form open the in design view.

  Form Form Text Radio

  c) Manipulating the ’s properties. Change the ’s property to and Size 576 240 Font BackColor the to , . Change the property to Tahoma. Set to PeachPuff .

  d) Adding the Preset Stations GroupBox and Button s. Add a GroupBox to the Form .

  Set its Size to 232, 64 , its Text to Preset 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 , respec- tively.

  Tutorial 3 Welcome Application

  23 e) Adding the Speakers GroupBox CheckBox Add a GroupBox to the Form . Set and es. its Size to 160, 72 , its Text to Speakers and its ForeColor to Black . Set its Loca- tion to 280 , 16 . Add two CheckBox es to the Form . Set each CheckBox ’s Size to 56 , 24 . Set the Text properties for the CheckBox es to Rear and Front .

  f) 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 .

  g) Adding the Volume Control GroupBox , the Mute CheckBox and the Volume Track- Bar . 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 and its Size to 56, 24 .

  Add a TrackBar to the GroupBox .

  h) Adding the Tuning GroupBox , the radio station Label and the AM/FM RadioBut- ton s. Add a GroupBox to the Form . Set its Text to Tuning , its ForeColor to Black Introduction to Visual Programming Solutions Tutorial 3

  24 BackColor RosyBrown Font Bold Size 216,

  80 and its to . Set its style to and its to . Label Form BackColor PeachPuff ForeColor Black

  Add a to the . Set its to , its to , BorderStyle FixedSingle Font Bold TextAlign Middle- its to , its style to , its to Center Size

  56

  23 Tex

  92.9 Label and its to , . Set its t to . Place the as shown in the

  RadioButton GroupBox BackColor Peach- figure. Add two s to the . Change the to Puff Size 40,24 Text AM Text FM and change the to . Set one’s to and the other’s to .

i) Adding the image. Add a PictureBox to the Form . Set its BackColor to Transpar-

  ent , its SizeMode to StretchImage and its Size to 56 , 72 . Set its Image property to C:\Examples\Tutorial03\ExerciseImages\Radio\MusicNote.gif . j) Saving the project. Select File > Save All to save your changes. k) Closing the IDE. Close Visual Studio .NET by clicking its close box.

  25 T U T O R

  I A L

  4 Designing the Inventory Application

  Introducing TextBoxes and Buttons Solutions

  Tutorial 4 Designing the Inventory Application

  26 Instructor’s Manual Exercise Solutions

  Tutorial 4 4.1 A new Windows application is created by selecting from the File menu. MULTIPLE-CHOICE

  a) New > Program b) New > File… QUESTIONS

  c) New > Project… d) New > Application Label BorderStyle 4.2 A ’s property can be set to .

  Fixed3D Single

  a)

  b)

  3D

  c) d) All of the above.

  Label Label 4.3 When creating a , you can specify the of that .

  a) alignment of the text

  b) border style

  c) size d) All of the above.

  Form

4.4 Changing the value stored in the property will change the name of the file.

  Name File

  a)

  b)

  c) File Name

  d) Full Path TextBox

4.5 should be used to prefix all names.

txt tbx

  a)

  

b)

Frm tbn

  c)

  

d)

  4.6 A(n) helps the user understand a control’s purpose.

  Button Label

  a)

  b) descriptive Label

  c) output

  d) title bar 4.7 A is a control in which the user can enter data from a keyboard.

  Button TextBox

  a)

  b) Label PictureBox

  c)

  d) Label 4.8 A descriptive uses .

  a) sentence-style capitalization

  b) book-title capitalization

  c) a colon at the end of its text d) Both a and c.

  4.9 You should use the font in your Windows applications.

  a) Tahoma

  b) MS Sans Serif

  c) Times

  d) Palatino Button

4.10 should be used to prefix all names.

but lbl

  a)

  

b)

Frm btn

  c)

  

d)

Answers:

  4.1)

  c. 4.2)

  a. 4.3)

  d. 4.4)

  c. 4.5)

  a. 4.6)

  b. 4.7)

  b. 4.8)

  d. 4.9)

  a. 4.10) d.

  At the end of each tutorial, you will find a summary of new GUI design tips listed in the EXERCISES

  GUI Design Guidelines section. A cumulative list of GUI design guidelines, organized by control appears in Appendix C. In these exercises, you will find C# Form s that do not fol- low the GUI design guidelines presented in this tutorial. For each exercise, you must mod- ify control properties so that your end result is consistent with the guidelines presented in the tutorial. Note that these applications do not provide any functionality.

  (Address Book

4.11 GUI) In this exercise, you apply the GUI design guidelines you have learned to a graphical user interface for an address book (Fig. 4.22).

  

Introducing TextBoxes and Buttons Solutions Tutorial 4

  27

Figure 4.22 Address Book application without GUI design guidelines applied.

  a) Copying the template to your working directory. Copy the directory C:\Examples\ Tutorial04\Exercises\AddressBook to your C:\SimplyCSP directory.

  b) Opening the application’s template file. Double click AddressBook.sln in the AddressBook directory to open the application. Double click AddressBook.cs in the Solution Explorer window to open the Form in design view.

  c) Applying GUI design guidelines. Rearrange the controls and modify their properties so that the GUI conforms to the design guidelines you have learned. Add new con- trols as necessary.

  d) Saving the project. Select File > Save All to save your changes.

  e) Closing the IDE. Close Visual Studio .NET by clicking its close box.

  Answer: 1. Change the Form ’s title ( Text property).

  TextBox Label

2. All es should have corresponding s.

  3. Label s indicating control usage should use sentence-style capitalization.

  4. Button s should use book-title capitalization.

  5. Each descriptive Label text should end with a colon.

4.12 In this exercise, you apply the GUI design guidelines you

  (Mortgage Calculator GUI) have learned to a graphical user interface for a mortgage calculator (Fig. 4.23).

  Tutorial 4 Designing the Inventory Application

  28 Mortgage Calculator application without GUI design guidelines

Figure 4.23 applied.

  C:\Examples\

  a) Copying the template to your working directory. Copy the directory Tutorial04\Exercises\MortgageCalculator to your C:\SimplyCSP directory.

  b) Opening the application’s template file. Double click MortgageCalculator.sln in MortgageCalculator Mortgage- the directory to open the application. Double click Calculator.cs in the Solution Explorer window to open the Form in design view.

  c) Applying GUI design guidelines. Rearrange the controls and modify their properties so that the GUI conforms to the design guidelines you have learned.

  d) Saving the project. Select File > Save All to save your changes.

  e) Closing the IDE. Close Visual Studio .NET by clicking its close box.

  Answer: 1. Label should be placed above or to the left of the control it is describing.

  2. Output Label ’s setting should be BorderStyle property Fixed3D .

  3. Output Label initially should be blank.

  4. Place an application’s output below or to the right of the Form ’s input control.

4.13 In this exercise, you apply the GUI design guidelines you have

  (Password GUI) learned to a graphical user interface for a password-protected message application (Fig. 4.24). Introducing TextBoxes and Buttons Solutions Tutorial 4

  29 Multiline TextBox (you will learn how to create these in later tutorials)

Figure 4.24 Password application without GUI design guidelines applied.

  a) Copying the template to your working directory. Copy the directory C:\Examples\ Tutorial04\Exercises\Password to your C:\SimplyCSP directory.

  b) Opening the application’s template file. Double click Password.sln in the Pass- word directory to open the application. Double click Password.cs in the Solution Explorer window to open the Form in design view.

  c) Applying GUI design guidelines. Rearrange the controls and modify their properties so that the GUI conforms to the design guidelines you have learned.