Visual Basic Reference
- Activate occurs when an object becomes the active window.
- Deactivate occurs when an object is no longer the active window.
Private Sub object_Activate( )
Private Sub object_Deactivate( )
The object placeholder represents an object expression that evaluates to an object in the Applies To list.
An object can become active by user action, such as clicking it, or by using the Show or SetFocus methods in code.
The Activate event can occur only when an object is visible. For example, a form loaded with the Load statement isn't visible unless you use the Show method or set the form's Visible property to True.
The Activate and Deactivate events occur only when moving the focus within an application. Moving the focus to or from an object in another application doesn't trigger either event. The Deactivate event doesn't occur when unloading an object.
The Activate event occurs before the GotFocus event; the LostFocus event occurs before the Deactivate event.
These events occur for MDI child forms only when the focus changes from one child form to another. In an MDIForm object with two child forms, for example, the child forms receive these events when the focus moves between them. However, when the focus changes between a child form and a non-MDI child form, the parent MDIForm receives the Activate and Deactivate events.
If an .exe file built by Visual Basic displays a dialog box created by a .dll file also built in Visual Basic, the .exe file's form will get the Deactivate and LostFocus events. This may be unexpected, because you should not get the Deactivate event:
- If the object is an out-of-process component.
- If the object isn't written in Visual Basic.
- In the development environment when calling a DLL built in Visual Basic.