Activate, Deactivate Events

See AlsoEFSU2D              Example2IWWGRK>Low

Apply To

Form14TJ2LN, MDI form1ILMZQ7.

Description

         Activateoccurs when a form becomes the active windowMGLJZ1.

         Deactivateoccurs before a different form becomes the active window.

Syntax

Sub Form_Activate ( )

Sub MDIForm_Activate ( )

Sub Form_Deactivate ( )

Sub MDIForm_Deactivate ( )

Remarks

A form can become active by user action, such as clicking a form or control, or by using the Show2IF9Z3Q or SetFocus4AVBOY methods in code.

The Activate event can occur only when a form is visible.  For example, a form loaded with the LoadGU0759 statement is not visible unless you use the Show method or set the form's Visible32KNZA4 property to True.

The Activate and Deactivate events occur only when moving the focus within an application.  Moving the focus to or from a form in another application does not trigger either event.  The Deactivate event does not occur when unloading a form.

The Activate event occurs before the GotFocus32EWUCC event; the LostFocus2ZXQDAR event occurs before the Deactivate event.

These events occur for MDI child formsEXWLAX only when the focus changes from one child form to another.  In an MDI form 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 gets the Activate and Deactivate events.


See Also

Help:

GotFocus Event32EWUCC

LostFocus Event2ZXQDAR

SetFocus Method4AVBOY

Show Method2IF9Z3Q

Using MDI FeaturesHOWMDI

 

Programmer's Guide:

Chapter 14, "Multiple-Document Interface (MDI) Applications"


Activate, Deactivate Events Example

The example updates a status bar with the caption of the active form.  To try this example, create a form (Form1) and a new MDI form (MDIForm1).  On the MDI form, draw a picture box containing a label.  On Form1, set the MDIChild property to True.  Paste the MDIForm_Load event code into the Declarations section of the MDI form.  Paste the Form_Activate event code into the Declarations section of the MDI child form.  Then press F5.

Sub MDIForm_Load ()

   Form1.Caption = "Form #1"       ' Set caption of Form1.

   Dim NewForm As New Form1        ' Create a new child form.

   Load NewForm

   NewForm.Caption = "Form #2"     ' Set caption of new form.

   NewForm.Show                    ' Display the new form.

End Sub

 

Sub Form_Activate ()

   ' Set status bar text.

   MDIForm1.Label1.Caption = "Current form: " & Me.Caption

End Sub