Sams Teach Yourself Visual Basic 6 in 24 Hours
- Table of Contents
- Copyright
- About the Author
- Acknowledgments
- Introduction
- Who Should Read This Book
- What This Book Will Do for You
- Can This Book Really Teach Visual Basic in 24 Hours?
- What You Need
- Files on the Visual Basic Distribution CD-ROM
- Conventions Used in This Book
- Enough! Time Is Ticking!
- Part I: Introducing Visual Basic
- Hour 1. Visual Basic at Work
- Hour 2.Analyzing Visual Basic Programs
- Hour 3.Controls and Properties
- Hour 4.Examining Labels, Buttons, and Text Boxes
- Understanding Control Focus at Runtime
- The Mouse and Hotkeys Need No Focus
- Related Properties
- Tab Order
- Command Buttons
- Labels
- Text Boxes
- Form Properties
- Summary
- Q&A
- Workshop
- Part II: Coding the Details
- Hour 5.Putting Code into Visual Basic
- Hour 6.Message and Input Boxes
- Hour 7.Making Decisions
- Hour 8.Visual Basic Looping
- Part III:Putting Code to Work
- Hour 9.Combining Code and Controls
- Hour 10.List Boxes and Data Lists
- Hour 11.Additional Controls
- Hour 12.Dialog Box Basics
- Part IV:Programming with Data
- Hour 13.Modular Programming
- Hour 14.Built-In Functions Save Time
- Hour 15.Visual Basic Database Basics
- Hour 16.Printing with Visual Basic
- Part V:Sprucing Up Programs
- Hour 17.Menus and Visual Basic
- Hour 18.The Graphic Image Controls
- Hour 19.Toolbars and More Graphics
- Hour 20.Writing Correct Applications
- Part VI:Advancing Visual Basic Applications
- Hour 21.Visual Basic and ActiveX
- Hour 22.Object Basics
- Hour 23.Distributing Your Applications
- Hour 24.Online Visual Basic
- Part VII:Appendixes
- Appendix A.Operator Precedence
- Appendix B.Answers
- Appendix C.Using the CD-ROM
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.
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.
Figure 4.2 One of these seven command buttons has the focus.
The Mouse and Hotkeys Need No Focus | Next Section

Account Sign In
View your cart