views:

24

answers:

2

I have a mdi and 3 child windows. The program start with an empty mdi. With a menu you can open each child window once.

When i open for example 2 windows. And close the one on top. The one left(the window under the one i closed) should get focus. How can i manage this?

why i need this? each childwindow has a event gotFocus. Depending on the focus my menu should change.

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

ty in advance :))

A: 

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.

George
A: 

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.

Hans Passant