GotFocus() and MDI Children
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 activ开发者_C百科e 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
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.
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.
精彩评论