Activate, Deactivate Events

Purpose

Activate - occurs when an object becomes the active window.

Deactivate - occurs when an object is no longer the active window.

Syntax

Sub Form_Activate( [Index%] )

Sub Form_Deactivate([Index%])

Description

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

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 MdiParent form 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 MDI Form receives the Activate and Deactivate events.

Example

Form frm1 = "Activate, Deactivate Events", 20, 20, 300, 300

Do

Sleep

Until Me Is Nothing

 

Sub frm1_Activate

Print "Form Activated"

EndSub

 

Sub frm1_Deactivate

Print "Form Deactivated"

EndSub

See Also

Form, GotFocus, LostFocus, SetFocus, Activate

{Created by Sjouke Hamstra; Last updated: 23/09/2014 by James Gaite}