Full file at http://testbank360.eu/solution-manual-programming-in-visual-basic-2010-1st-edition-bradley

Chapter 2

User Interface Design

OBJECTIVES:

Upon completion of this chapter, your students will be able to

  1. Use text boxes, masked text boxes, rich text boxes, group boxes, check boxes, radio buttons, and picture boxes effectively.
  2. Set the BorderStyle property to make controls appear flat or three-dimensional.
  3. Select multiple controls and move them, align them, and set common properties.
  4. Make your projects easy for the user to understand and operate by defining access keys, setting an Accept and a Cancel button, controlling the tab sequence, resetting the focus during program execution, and causing ToolTips to appear.
  5. Clear the contents of text boxes and labels.
  6. Make a control visible or invisible at run time by setting its Visible property.
  7. Disable and enable controls at design time and run time.
  8. Change text color during program execution.
  9. Code multiple statements for one control using the With and End With statements.
  10. Concatenate (join) strings of text.
  11. Download the line and shape controls, add them to the toolbox, and use the controls on your forms.

2-1

Full file at http://testbank360.eu/solution-manual-programming-in-visual-basic-2010-1st-edition-bradley

Chapter Highlights:

OBJECTS / PROPERTIES / PROPERTIES / METHODS / STATEMENTS
CheckBox / AcceptButton / Text / Enable / With
GroupBox / BorderStyle / TextAlign / Focus / End With
LineShape / CancelButton / ToolTip on ToolTip1
MaskedTextBox / Checked / Visible
OvalShape / ForeColor / WordWrap
PictureBox / Image
RadioButton / Multiline
RectangleShape / SizeMode
RichTextBox / StartPosition
Text box / TabIndex
ToolTip component / TabStop

CHAPTER OUTLINE:

  1. Introducing More Controls
  2. Text Boxes ! Review Question 1

Text boxes are used primarily for user input. The Text property holds the value input by the user. You also can assign a literal to the text property during design time or run time.

Text Boxes have a Multiline and WordWrap property that can allow a long Text property to wrap to multiple lines. The text will wrap to the width of the control, which must be tall enough to display multiple lines.

  1. Masked Text Boxes ! Review Question 2

A MaskedTextBox has a Mask property that allows you to specify the data type and format of the input data.

  1. Rich Text Boxes ! Review Question 3, 4

A RichTextBox is a specialized text box that allows additional formatting of the text.

RichText Boxes have a Multiline and WordWrap property that can allow a long Text property to wrap to multiple lines. The text will wrap to the width of the control, which must be tall enough to display multiple lines.

  1. Displaying Text on Multiple Lines
  2. Group Boxes

Group boxes are used as containers for other controls and to group like items on a form.

  1. Check Boxes
  2. Radio Buttons ! Review Question 5, 6

Check boxes and radio buttons allow the user to make choices. In a group of radio buttons, only one can be selected; but in a group of check boxes, any number of the boxes may be selected.

The current state of check boxes and radio buttons is stored in the Checked property; the CheckChanged event occurs when the user clicks on one of the controls.

  1. Picture Boxes ! Review Question 7

Picture box controls hold a graphic, which is assigned to the Image property. Set the SizeMode property to StretchImage to make the image resize to fit the control.

  1. Using Smart Tags
  2. Using Images for Forms and Controls

The Resources tab of the Project Designer can be used to add, remove, and rename images in the project Resources folder.

Forms and controls can display images from the project’s resources. Use the form’s BackgroundImage property and a control’s Image property.

  1. Setting a Border and Style

The BorderStyle property of many controls can be set to None, Fixed Single, or Fixed3D, to determine whether the control appears flat or three-dimensional.

  1. Drawing a Line

Use a Label control to create a line on a form.

II.  Working with Multiple Controls ! Review Question 8

  1. Selecting Multiple Controls

You can select multiple controls and treat them as a group, including setting common properties at once, moving them, or aligning them.

  1. Deselecting a Group of Controls
  2. Moving Controls as a Group
  3. Setting Properties for Multiple Controls
  4. Aligning Controls
  1. Designing Your Applications for User Convenience
  2. Designing the User Interface

Make your programs easier to use by following Windows standard guidelines for colors, control size and placement, access keys, default and Cancel buttons, and tab order.

  1. Defining Keyboard Access Keys ! Review Question 9

Define keyboard access keys by including an ampersand in the Text property of buttons, radio buttons, check boxes, and labels.

  1. Setting the Accept and Cancel Buttons ! Review Question 10

Set the AcceptButton property of the form to the desired button so that the user can press Enter to select the button. If you set the form's CancelButton property to a button, that button will be selected when the user presses the Esc key.

D.  Setting the Tab Order for Controls ! Review Question 12, 13

The focus moves from control to control as the user presses the Tab key. The sequence for tabbing is determined by the TabIndex properties of the controls. The Tab key stops only on controls that have their TabStop property set to True.

  1. Setting the Form’s Location on the Screen

F.  Creating ToolTips ! Review Question 11

Add a ToolTip control to a form and then set the ToolTip on ToolTip1 property of a control to make a ToolTip appear when the user pauses the mouse pointer over the control. You can set the properties of the ToolTip component to modify the background, the foreground, shape, and an icon for the ToolTips.

  1. Coding for the Controls

A.  Clearing Text Boxes and Labels ! Review Question 15

Clear the Text property of a text box or a label by setting it to an empty string. Text boxes also can be cleared using the Clear method.

B.  Resetting the Focus ! Review Question 14

To make a control have the focus, which makes it the active control, use the Focus method. Using the Focus method of a text box makes the insertion point appear in the text box. You cannot set the focus to a disabled control.

  1. Setting the Checked Property of Radio Buttons and Check Boxes

You can set the Checked property of a radio button or check box at run time and also set the Visible property of controls in code.

  1. Setting Visibility at Run Time
  2. Disabling Controls

Controls can be disabled by setting the Enabled property to False.

  1. Setting Properties Based on User Actions
  2. Changing the Color of Text

Change the color of text in a control by changing its ForeColor property.

You can use the color constants to change colors during run time.

H.  Using Radio Buttons for Selecting Colors

I.  Changing Multiple Properties of a Control ! Review Question 16

The With and End With statements provide an easy way to refer to an object multiple times without repeating the object’s name.

  1. Concatenating Text ! Review Question 17

Joining two strings of text is called concatenation and is accomplished by placing an ampersand between the two elements. (A space must precede and follow the ampersand.)

  1. Continuing Long Program Lines ! Review Question 18

v  Visual Basic 2010 offers implicit line continuation as well as the traditional:Use a space and an underscore to continue a long statement on another line. Be sure to demonstrate implicit continuation!

  1. Downloading and Using the Line and Shape Controls
  1. Your Hands-On Programming Example
  2. Planning the Project
  3. The Project Coding Solution
  4. Good Programming Habits
  5. Summary
  6. Key Terms
  7. Review Questions
  8. Programming Exercises
  9. Case Studies

TEACHING SUGGESTIONS:

·  You can use any graphic file (with the proper format) that you have available.

·  Demonstration Idea: The hands-on example in the back of chapter 2 can be used as your demonstration model. The example uses many of the new controls and topics introduced in this chapter. The Basic code used in the example is brief, and will keep your student's attention. Begin by explaining the purpose of the project and talk through, or write on the board, each of the three planning steps: (1) sketch the form, (2) list the objects and properties that are needed, and (3) plan the code that will be used for each of the procedures that will execute when your project runs.

·  Chapter 2 introduces many new objects and properties. Beginners are often confused about the difference between labels and text boxes. Give examples of situations where text boxes are used, such as a form that will be filled in for an employment application. Remember, a user can change what is displayed in a text box.

·  There are many options available for customizing the user interface. The BorderStyle property is used for displaying controls as flat or 3D. The TextAlign property is used to change the alignment of the text in text boxes. The ForeColor (color of text) property can be used to enhance the appearance of the user interface. Recommend that your students read "Designing the User Interface" from Chapter 2. This section of the text suggests colors and fonts that are "comfortable" for the user.

·  The MaskedTextBox and the RichTextBox controls are specialized forms of the TextBox control. With the MaskedTextBox you can specify the format of the data required of the user by selecting from the options in the Mask property. The RichTextBox allows formatting within the box.

·  Deciding whether to use a radio button or a check box can be confusing. Quiz your students on what would be used in each of these situations on a credit application:
Your income range—below $25,000, $25,000 to $59,999, above $60,000 (radio buttons)
The ages of your children—under 3, 4-6, 7-10, 11-13, over 13 (check boxes)
Number of years with current employer—less than 1, 2-4, 5 or more (radio buttons)
Types of current credit—Department Store, Gasoline, Home Loan, Other (check boxes)

·  Pictures can be placed on a form with a PictureBox control. Images are added to a project using the Resources dialog box. This dialog box appears when the programmer clicks on the Image property and clicks on the properties button.

·  Demonstrate how controls can be selected individually or as a group. Show how controls can be moved as a group and properties can be set as a group. Demonstrate how multiple controls can be aligned by selecting the group and then using the buttons on the Layout toolbar or the corresponding items on the Format menu.

·  HELPFUL HINT! To change the picture in the form’s Title bar, change the form’s Icon property.

·  Explain that user convenience is important. Changing the Text property to include the "&" will allow keyboard access with the ALT key. Emphasize that programmers should be careful not to assign duplicate access keys on the same form.

·  Demonstrate how you can make one of your buttons the default button by setting the AcceptButton property of the form to the button name. When the user presses ENTER, that button is automatically selected and the code in the button executes. Also, demonstrate how you can select a cancel button. The cancel button is the button that is selected when the user presses the ESC key. You can make a button the cancel button by setting the form's CancelButton property. Note that these are properties of the form.

·  Demonstrate and discuss the importance of having the tab key work properly by setting the TabIndex and TabStop properties. You can also view the tab indexes of all controls in the design view by selecting the View menu and then choosing Tab Order (the form must be displayed).

·  Show how you can set the StartPosition property of a form to specify its location when the form is displayed. This is useful for all forms that are not maximized.

·  Add a Tooltip to a control and then run the program and let the mouse pointer pause over the object. Note that a ToolTip component must be added to the component tray in order for the controls on the form to have the Tooltip on ToolTip1 property.

·  COMMON ERROR: When students write code to clear a text box or label, many times they will not use an empty string. The empty string is "" (no space between the two quotation marks). Often, students will type a blank space in between the quotes. This will cause them frustration in later chapters when they are validating text boxes for input and the test finds a blank space and identifies the object as not being empty.

·  Explain the use of the Focus method to make the insertion point appear in the correct object.

·  Note that the Checked property of radio buttons and check boxes can be tested for True or False to determine if they are selected.

·  Discuss the real advantage of using the With statement. Using With/EndWith is more efficient than spelling out the object in each statement. Your Visual Basic projects will run a little faster if you use With/EndWith. On a large, complicated project, the savings can be significant.

·  Practice concatenation with these examples:
MessageLabel.Text = "One, " & "Two, " & "Three"
NameLabel.Text = "John " & "Doe"
WeatherLabel.Text = "Hello, " & NameTextBox.Text & "! Today the weather is warm."
Don’t forget punctuation in your concatenation:
MessageLabel.Text = "Hello, my name is " & NameTextBox.Text & "."

·  Don’t forget to demonstrate implicit line continuation, new in Visual Basic 2010!

Chapter 2 – User Interface Design

ANSWERS TO REVIEW QUESTIONS

1.  You can display program output in a text box or a label. When should you use a text box? When is a label appropriate?

Use a text box control when you want the user to type some input. Use a label control when you want to display information that the user cannot change. Labels can be used to display a message or the result of a calculation.