Close floating windows

The title may be misleading. I have floating and non floating windows that can be opened based upon choices made by the user while using the main active window, when this main window is closed by the user, any subsequent window that was opened by the user should close with it. How can I accomplish that?

Some are implicit instance and others not.

Keep a reference of the windows to be opened/closed and close them in the main window’s close event.

Hi Alex, that was my first attempt but I must have done it totally wrong because the implicit instance windows actually opened at the time of close. if you have a method for doing this I would appreciate the effort.

Can you elaborate this a bit more?

Closes all open windows :

For i As Integer = 0 To WindowCount - 1 Dim w As Window = Window(i) If w <> Nil Then w.close End If Next

I use the showmodal method to gather any information that may have been missed before allowing the user to continue to the next process in the app. once this modal has appeared, if the user closes the main window, the modal window remains, I need the modal to close with the main window.

currently, I’m blocking the possibility of closing the main window by use of Mutex but this is risky because I’m afraid I’ll end up with a hole in my code that allows the Mutex to remain causing more issues.

Hi Michael, that seems simple enough. I assume that would go in the close event of the main window… thank you!

Yes, putting it in the main window close closes all windows. If you want to keep one window open, place a condition in the loop like :

If w <> Nil and w<> Mywindow Then w.close End If