See Also Example1 Example2
Applies To
MDI form, Screen object
Description
Specifies the form that is the active window, If an MDI form is active, or if an MDI form is referenced, specifies the active MDI child form. Not available at design time; read-only at run time.
Usage
{ mdiform|Screen}.ActiveForm
Remarks
Use the ActiveForm property to access a form's properties or to invoke its methodsfor example, Screen.ActiveForm.Mousepointer = 4.
This property is especially useful in an MDI application where a button on a toolbar must initiate an action on a control in a MDI child form. When a user clicks a Copy button on the toolbar, your code can reference the text in the active control on the MDI child formfor example, ActiveForm.ActiveControl.SelText.
When a control on a form has the focus , that form is the active form on the screen (Screen.ActiveForm). In addition, an MDI form can have one child form that is the active form within the context of the MDI parent (MDIForm.ActiveForm). The ActiveForm on the screen is not necessarily the same as the ActiveForm in the MDI form, such as when a dialog form is active. For this reason, you should specify the MDI form with ActiveForm when there is a chance of a dialog being the ActiveForm.
Note When an active MDI child form is not maximized, the title bars of both the parent form and the child form appear active.
If you plan to pass Screen.ActiveForm or MDIForm.ActiveForm to a procedure, you must declare the argument in that procedure with the generic type (As Form) rather than a specific form type (As MyForm)even if ActiveForm always refers to the same type of form.
Data Type
Form
Help:
Activate, Deactivate Events
MDIChild Property
Programmer's Guide:
Chapter 14, "Multiple-Document Interface (MDI) Applications"
The example prints the time on the currently active child form in an MDI form. To try this example, create an MDI form, draw a picture box on it and draw a command button in the picture box. In Form1, set the MDIChild property to True. (You can also set AutoRedraw to True to keep text on the form even after covering it with another form.) Paste the appropriate code into the Declarations section of each form and press F5.
' Copy this code into the MDI form.
Sub MDIForm_Load ()
Dim NewForm As New Form1 ' Create new instance of Form1.
NewForm.Show
End Sub
' Copy this code into Form1.
Sub Command1_Click ()
' Print the time on the current form.
ActiveForm.Print "The time is " & Format(Now, "Long Time")
End Sub