Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

Understanding Control Focus at Runtime

The currently active control at runtime has the focus.

Before looking at this lesson's three controls, you need to master the concept of focus. Focus is a runtime concept. At runtime, only one window, form (which appears as a window), or control can have the focus. The window or form currently in focus is the form whose title bar is highlighted (typically colored blue). The control with the current focus has an outlined border or caption.

Focus is important because the focus determines what the next keystroke or Enter keypress will activate. For example, consider the screen shown in Figure 4.1. The figure shows a VB session with several windows, including two windows from the executing program. The center window is the window with the focus, and you know this because the title bar is highlighted. Therefore, the center window is the window that receives keystrokes if and when the user presses a key.

04fig01.gif

Figure 4.1 Learning to spot the window and control with focus.

Only one control on the active window can have the focus. The AutoSize check box has the current focus. Notice the outline around the control. Despite the other windows on the screen at the time, if the user presses Enter under Figure 4.1's circumstances, the check box receives that Enter keystroke. If you understand the way check boxes work, you know that a check box is either checked or unchecked, meaning that the control determines one of two states. If the user presses Enter, the AutoSize check box will turn to unchecked.

Different controls display the focus in different ways. Only one of the seven command buttons in Figure 4.2 can have the focus at any one time. Can you spot the command button that has the focus? The extra dotted outline around the Images command button lets you know that the Images command button has the focus and that command button will receive an Enter keypress if the user presses Enter.

04fig02.gif

Figure 4.2 One of these seven command buttons has the focus.

Share ThisShare This

Informit Network