See Also Example
Apply To
Form, MDI form
Description
Activateoccurs when a form becomes the active window .
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 Show
The Activate event can occur only when a form is visible. For example, a form loaded with the Load statement is not 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 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 GotFocus
These events occur for MDI child forms 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.
Help:
GotFocus Event
LostFocus Event
SetFocus Method
Show Method
Using MDI Features
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