VB6 beginners tutorial - Learn VB6

Advanced VB6 tutorial - Learn Advanced VB6

Systems Analysis - System analysis and Design tutorial for Software Engineering

You are here: Visual Basic > Advanced VB6 tutorial > Chapter 6

Activate/DeActivate Versus GotFocus/LostFocus Events

As noted earlier, a form is the active form in an application when the focus in the application is within that form. This could mean that either the form itself has the focus or that a control on the form has focus. The user can tell which form is active because the title bar appears highlighted, and the form usually appears on top of the user';s desktop.

A form receives an Activate event when it becomes the active form and a Deactivate event when it loses its active status to another form in the same application. The Activate and Deactivate event procedures are ideal places to put code that needs to react to the user';s navigation between forms.

Forms also support GotFocus and LostFocus events, as do controls. You might think that GotFocus and LostFocus event procedures would be good places to put code that reacts to a user entering and leaving a form in a multi-form application.

However, a form';s GotFocus and LostFocus events do not usually fire: A form can only receive focus if it contains no visible enabled controls. Because most forms have at least one visible enabled control, GotFocus and LostFocus don';t normally fire on forms when the user moves between forms in an application.

NOTE 1 : Choosing Between the Activate and Load Events. When a form first loads into memory and immediately displays (either because it';s the application';s startup form or because, say, you';ve used the Show method to load the form), the Activate event happens after the Load event. The Activate event procedure is a better place than the Load event procedure to put startup code that affects the form';s appearance (such as calls to the graphics methods) or code that manipulates Data-Bound controls.

This is because the Load event happens a bit too early for some of these operations to have their proper effect. In fact, putting some types of code in the Load event procedure can cause a runtime error if the code tries to manipulate runtime properties of controls that aren';t fully initialized.

NOTE 2 : Navigation Events Happen Only With Respect to the Current application. Activate, DeActivate, GotFocus, and LostFocus occur only with respect to movement between forms within the current application. When the user changes to or returns from another application, none of these events occur.


<< Previous | Contents | Next >>

Home | About Us | Privacy Policy | Contact Us

Copyright © | All Rights Reserved