Another important issue in form design is the tab order of the controls on the form. As you know, pressing the Tab key at runtime takes you to the next control on the form. The order of the controls is the order in which they were placed on the form, but this is never what we want. When you design the application, you can specify in which order the controls receive the focus (the tab order, as it is known) with the help of the TabIndex property. Each control has its own TabIndex setting, which is an integer value. When the Tab key is pressed, the focus is moved to the control whose tab order immediately follows the tab order of the current control. The values of the TabIndex properties of the various controls on the form need not be consecutive.
To specify the tab order of the various controls, you can set their TabIndex property in the Properties window or you can choose the Tab Order command from the View menu. The tab order of each control will be displayed on the corresponding control, as shown in Figure 5.3.
Figure 5.3 – Setting the Tab order by using the TabIndex property of the form
To set the tab order of the controls, click each control in the order in which you want them to receive the focus. You must click all of them in the desired order, starting with the first control in the tab order. Each control’s index in the tab order appears in the upper-left corner of the control. When you’re finished, choose the Tab Order command from the View menu again to hide these numbers.
As you place controls on the form, don’t forget to lock them, so that you won’t move them around by mistake as you work with other controls. You can lock the controls in their places either by setting each control’s Locked property to True or by locking all the controls on the form at once via the Format > Lock Controls command.
Design with the User In Mind
Designing functional forms is a crucial step in the process of developing Windows applications. Most data-entry operators don’t work with the mouse, and you must make sure that all the actions (such as switching to another control, opening a menu, clicking a button, and so on) can be performed with the keyboard. This requirement doesn’t apply to graphics applications, of course, but most applications developed with VB are business applications, and users should be able to perform most of the tasks with the keyboard, not with the mouse.
In my experience, the most important aspect of the user interface of a business application is the handling of the Enter keystroke. When a TextBox control has the focus, the Enter keystroke should advance the focus to the next control in the tab order; when a list control (such as the ListBox or ListView control) has the focus, the Enter keystroke should invoke the same action as double-clicking the current item. The sample project in the following section demonstrates many of the features you’d expect from a data-entry application.
If you’re developing a data-entry form, you must take into consideration the needs of the users. Make a prototype and ask the people who will use the application to test-drive it. Listen to their objections carefully, collect all the information, and then use it to refine your application’s user interface. Don’t defend your design — just learn from the users. They will uncover all the flaws of the application and they’ll help you design the most functional interface. In addition, they will accept the finished application with fewer objections and complaints if they know what to expect.