0
votes

I have an MDI form with 3 child windows.

  • The MDI starts empty.

  • Each child can be opened once from the menu.

When I open multiple windows, and close the top one should get focus, but the new active child-form's GotFocus() event is not firing.

Private Sub frmMain_gotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.GotFocus
...
End Sub
2

2 Answers

2
votes

Unlucky guess. Either the Enter or the Activated event will solve your problem.

In Windows Forms programming, you'd typically want to avoid the GotFocus and LostFocus events. They are often hidden in the designer, but not consistently. Respectively, the Enter and Leave events are their replacements, they are generated from the logical state of the UI instead of the raw Windows messages. Makes a difference when using Validating and MDI.

Activated is the "natural" one since the actual focus moves to a child control of that form.

0
votes

When you create the MDI children forms from the MDI parent, you should subscribe the MDI parent form to the MDI child form's GotFocus event. That when any focus events happen on your MDI Child, your MDI Parent gets notified.

When a form is closed/opened, the next child form in the MDI Z-Order should automatically be selected, and if you're subscribing to the event, your MDI parent can act appropriately and display your data.