The Active Child
the correct class.
Private Sub NewMenu_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles NewMenu.Click
Dim AnMDIChild As New ChildForm()
AnMDIChild.MdiParent = Me
AnMDIChild.Show()
End Sub
Build your application (from the Project menu's Debug, Start New Instance menu item). If your method is
implemented as shown in the above code, you'll be able to create new MDI child forms. By setting the
MDIlist property to True, we can see the enumeration of child windows in the Window menu, as illustrated
in Figure 16−5.
Figure 16−5: An MDI application with child windows
As mentioned earlier, if you place menus on the child form, they will be merged automatically with the menu
items of the parent, provided you have set the MergeType property of the main menu to MergeItems.
Additionally, you can also set the MergeOrder property so that the menu items from both menus appear in
the order you specify.
The Active Child
When you implement child forms in MDI applications, you need a way to reference the active form from
other forms and from the parent form. Seldom do you ever work with a child form in total isolation from the
rest of the application and its sibling forms. For example, how would you be able to copy text from one child
form's text editor to another child form's text editor without having access to the handles of source and target
objects?
You can obtain a reference on the active form by using the facility of the parent's ActiveMDIChild property.
The property returns to you the child form that currently has the focus, or the form that was the most recently
active.
In addition, you also need to have information about which control on a child form is active. This information
comes to you by way of the ActiveControl property. So, if we have more than one control active on a form,
this property lets us know which control is currently in focus, or being referenced.
The following code demonstrates the referencing of these properties, and thus of the various properties
exposed to the form objects:
Public Sub IndexCopy_Click(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles IndexCopy.Click
576