Set tab order
For example, suppose you set up two textbox names named Text1 and Text2, and then set up a CommandButton called Commandl. TEXT1 has focus when the application starts. Pressing the TAB key causes the focus to move between controls in the order in which the controls are established, as shown in Figure 3.20.
Setting the TabIndex property changes the tab order of a control. The TabIndex property of the control determines its position in the tab order. By default, the first established control has a TabIndex value of 0, a second TabIndex value of 1, and so on. When you change the tab order position of a control, Visual automatically renumber the tab order position of the other controls to reflect insertions and deletions. For example, to make Command1 the first in the tab order, the TabIndex value of other controls is automatically adjusted upward, as shown in the following table.
Because numbering starts at 0, the maximum value of TabIndex is always 1 less than the number of controls in the tab order. Visual basic converts this value to the number of controls minus one, even if the TabIndex property value is higher than the number of controls.
Note controls that do not have the focus and the invalid and invisible controls do not have the TabIndex property and are therefore not included in the tab order. When you press the TAB key, the controls are skipped.
To delete a control in the tab order
Typically, you can select each control in the tab order by pressing the TAB key at run time. You can remove this control from the tab order by setting the control's TabStop property to False (0).
The control whose TabStop property has been set to false still retains its position in the actual tab order, except that the control is skipped when the TAB key is pressed.
Note that a OptionButton group has only one tab station. The TabStop property of the selected button (that is, a button with a value of True) is automatically set to True, and the other button's TabStop property is false.
Menu Basics
If an application is to provide users with a set of commands, menus provide a convenient way to group commands and make it easy for users to access these commands.
Figure 3.21 illustrates the menu interface element of a untitled form.
The menu bar immediately appears under the title bar of the form and contains one or more menu headings. When you click a menu title (such as "file"), the list containing the menu items is pulled down. Menu items can include commands such as new and exit, separator bars, and submenu headings. Each menu item that the user sees corresponds to one that is defined in the menu editor (the menu editor is discussed later in this chapter).
To make your application easy to use, you should group menu items by their capabilities. For example, the file-related commands in Figure 3.21 are "new", "open", and "Save as" are listed on the File menu. Some menu items perform actions directly, such as the Exit menu item on the File menu closes the application. Other menu items display a dialog box that requires the user to provide a window into the information that the application needs to perform the action. You should add an ellipsis (...) to these menu items. For example, when you choose Save As ... from the File menu. , the Save File As dialog box appears.
A menu control is an object that, like other objects, has properties that define its appearance and behavior. You can set the Caption properties, Enabled and Visible properties, Checked properties, and other properties at design or run time. The menu control contains only one event, the Click event, that is invoked when the menu control is selected with the mouse or the keyboard.
For more information about menu controls, see "Creating a menu with the Menu Editor" in chapter sixth, "Creating a user interface."
pop-up menu
A pop-up menu is a floating menu that appears on top of a form, independent of the menu bar, as shown in Figure 3.22. The items that appear on the pop-up menu depend on the position of the pointer when the right mouse button is pressed, so the pop-up menu is also called the context menu (in Windows 95, the right mouse button activates the context menu.) Should use a pop-up menu to provide an efficient way to access public context commands. For example, if you right-click a TextBox, a context menu appears (as shown in Figure 3.22).
Any menus that have at least one menu item can be displayed as a pop-up menu at run time. Use the PopupMenu method to display the pop-up menu.
For more information about pop-up menus, see "Creating a menu with the Menu Editor" in chapter sixth, "Creating a user interface."
Using the Menu Editor
With the menu editor, you can add new commands to existing menus, replace existing menu commands with your own commands, produce new menus and menu bars, and change and delete existing menus and menu bars. The main advantage of the menu editor is ease of use. You can customize menus in a fully interactive way with little programming.
To display the menu editor,
From the Tools menu, select the menu editor, which opens the menu editor, as shown in Figure 3.23
Most Menu control properties can be set with the menu Editor, and all menu properties are also available in the Properties window. Typically, you create a menu in the menu editor, but you want to quickly change a single property, typically using the Properties window.
For more information about creating menus and using the menu editor, see "Creating a menu with the Menu Editor" in chapter sixth, "Creating a user interface."
Prompt the user with a dialog box
In windows-based applications, dialog boxes are used to prompt users for the data they need to run the application or to display information to the user. A dialog box is a special type of form object that can be established in one of the following three ways:
Code that uses the MsgBox or InputBox function can create a predefined dialog box.
Create a custom dialog box using a standard form or a custom existing dialog box.
Use the CommonDialog control to create standard dialog boxes, such as print and open files.
Figure 3.24 is an example of using the MsgBox function to create a predefined dialog box.
The dialog box is displayed when the MsgBox function is called in code. The code is as follows:
MsgBox "Error encountered while trying to open file," & VbCrLf & "Pleaseretry.", vbexclamation, "Text Editor"
You need to give the MsgBox function three or three parameters: Message text, constants that determine the type of dialog box (numeric value), and headings. Because styles can use a variety of combinations of buttons and icons, it is easier to create dialog boxes.
Because most dialog boxes require user interaction, they are usually displayed as modal dialogs. You must close (hide or uninstall) The modal dialog box before you continue to use other parts of the application. For example, if you have to click OK or cancel before you switch to another form or to another dialog box, the dialog box is the modal dialog box.
The modeless dialog box does not need to be closed to move the focus between the dialog box and other forms. When the dialog box is displayed, you can continue to work elsewhere in the current application. The modeless dialog box is rare, and is usually displayed because the application requires a response before continuing. The Find dialog box for the Edit menu in Visual Basic is a modeless dialog box. Use modeless dialog boxes to display commonly used commands or information.
For more information about creating a dialog box, see Chapter Sixth, "Creating a user interface."