Detecting MDI Child Window Activation

154 If the other menu items MergeType property is set to Add , both menu items appear in the target menu just as though both had specified Add . If the other menu items MergeType property is set to Remove , only this menu item appears in the target menu again, the same as specifying Add for this menu item. If the other menu items MergeType property is set to Replace , only the child forms menu item is displayed, regardless of which one is set to MergeItems and which one is set to Replace . This seems like inconsistent behavior and may be a bug. Remove The menu item isnt shown in the target menu, regardless of the setting of the other menu items MergeType property. Replace If the other menu items MergeType property is set to Add , both menu items appear in the target menu just as though both had specified Add . If the other menu items MergeType property is set to MergeItems or Replace , only the child forms menu item is shown. This seems like inconsistent behavior and may be a bug. If the other menu items MergeType property is also set to Replace , only the child forms menu item is shown.

4.4.4 Detecting MDI Child Window Activation

Code in the MDI parent form class can be notified when an MDI child form becomes active inside an MDI parent form. Active means that the child form receives the input focus after another MDI child form or the MDI parent form had the input focus. To receive such notification, the MDI parent form must override the OnMdiChildActivate method defined in the Form class. For example: Place this within the class definition of the MDI parent form. Protected Overrides Sub OnMdiChildActivateByVal e As EventArgs MyBase.OnMdiChildActivatee Important ... End Sub It is important to call the base-class implementation of OnMdiChildActivate within the overriding function, so that any necessary base-class processing including raising of the MdiChildActivate event can occur. The e parameter carries no information. To find out which MDI child form became active, read the ActiveMdiChild property of the MDI parent form. This property is of type Form. Convert it to the MDI child forms type to gain access to any public members that are specific to that type. For example: Protected Overrides Sub OnMdiChildActivateByVal e As EventArgs MyBase.OnMdiChildActivatee Assumes that SomeFormType is defined elsewhere and inherits from Form. Also assumes that the MDI child forms in the application are always of this type. Dim childForm As SomeFormType = _ CTypeActiveMdiChild, SomeFormType Do something with childForm here. ... 155 End Sub To have code outside of the MDI parent form class notified when an MDI child form becomes active, write a handler for the MDI parent forms MdiChildActivate event. This event is defined in the Form class as: Public Event MdiChildActivate _ ByVal sender As Object, _ ByVal e As EventArgs _ The sender parameter is the MDI parent form, not the MDI child form that has been activated. The e parameter does not contain any additional information about the event. As when overriding the OnMdiChildActivate method, read the MDI parent forms ActiveMdiChild property to discover which MDI child form has been activated.

4.5 Component Attributes