Visual Basic 2008 Programming: Business Applications with a Design Perspective
Chapter 1 Chapter 2 Chapter 3 Chapter 4 Chapter 5 Chapter 6 Chapter 7 Chapter 8 Chapter 9
Chapter 10 Chapter 11 Chapter 12 Chapter 13 Chapter 14 Appendix A Appendix B Appendix C Home
Last change: February 13 2016 18:48:19.

 Chapter in PDF

Table of Contents

Chapter 3: User Interface Design: Visual Basic Controls and Events
Last change: February 13 2016 18:47:26.

The Tab Control

Now consider the hospital account screen further. The data to be collected are far more detailed than what have been presented. For example, concerning personal data, the hospital needs not only the account holder’s name and address but also additional identification (such as gender and date of birth), phone numbers, spouse, and so on, not to mention additional information on the holder’s insurance. It is impractical, if not impossible, to include all these data elements in one screen, yet it is highly desirable to treat all these data as one single logical unit. You want to save, retrieve, and update all these data in a single operation. The VB control that can help handle this situation is the tab control. Figure 3-7 shows the TabControl icon and its initial appearance on a form.

Figure 3-7
The TabControl icon and appearance

You can set the number of tabs, each tab’s individual Text property as well as other properties in the TabPage Collection Editor dialog box. To access this dialog box, click the TabPages property in the control’s Properties window; then click the ellipsis button on the right of the box. With this dialog box, you can add a tab by clicking the Add button. You can set each individual tab’s properties, such as name, back color, text, and so on, by highlighting the tab name in the upper left box and then setting the properties in the Properties window on the right (Figure 3-8). To remove a tab, highlight the tab name and click the Remove button.
Similar to the group box, each of these tabs serves as a container. Various VB controls, including the group box, can be drawn in it. At run time, the user can move between these tabs by clicking the tab captions. The control’s SelectedIndex property value tells you which tab your user is working on. (The first tab has a SelectedIndex value of 0.) You can also use code to change the tab by assigning a value to the control’s SelectedIndex property. For example, the following statement will make a tab control named tabAcctInfo show its third tab. (Note again the SelectedIndex property for the first tab is 0.)

tabAcctInfo.SelectedIndex = 2

Figure 3-9 shows the redesigned—but still simplified—hospital account holder entry form, using the tab control as the main grouping device. To create the interface on a new form, follow these steps:

  1. Draw a tab control onto the form and adjust the size of the control.
  2. Invoke the tab’s TabPage Collection Editor dialog box, as illustrated in Figure 3-8.
  3. In the dialog box, add the number of tabs to five by clicking the Add button repetitively.
  4. Set the individual tab’s Text properties.
  5. Click TabPage1 in the left box.
  6. Set the Text property in the Properties window on the right of the dialog box. Make it show Account.
  7. Set the Text properties for all other tabs in the same manner.
  8. Draw controls into the first tab. Notice that there is a group box used to group the radio buttons for gender. You may want to draw the group box first. (The radio button is discussed in the next section, but drawing the control on the form is the same as drawing other controls.)
  9. Draw controls onto the other tabs. The details, including fields to include, are left up to you.
  10. Draw the buttons onto the form. Notice that they are not drawn inside the tab control. Change the Text properties of these buttons as well as the form.

Figure 3-8
The TabPages Properties window and TabPage Collection Editor dialog box

Figure 3-9
Sample use of tab control for visual interface

More discussion on the tab control is presented in Chapter 10, “Special Topics in Data Entry.” The following table lists the new properties discussed in this section.

Property Applicable Object Use/Remark
Visible The form and all controls that can appear during runtime The object will be visible if this property is set to True; invisible, if False. For example, the code
lblAddress.Visible = False
will make the label lblAddress disappear.
Enabled The form and all controls To enable or disable a control; a disabled control cannot receive focus and thus cannot accept any user input; an object is enabled if this property is set to True; disabled, if False. The code grbID.Enabled = False will disable all controls in the group box named grbID.
SelectedIndex Tab To set or return the tab’s index position; for example, the code tabAccount.SelectedIndex = 1 will show the second tab of the tab control named tabAccount.
Last change: February 13 2016 18:47:28.