Link to home
Start Free TrialLog in
Avatar of twibblejaway
twibblejaway

asked on

Closing all windows and returning to main menu

When my program starts it has a main menu.  Depending on the options the user selects there can be up to 4 windows open.  At this point I have a timer which counts down to 0, and when it reaches 0 I want to close all of the windows and return to the main window.  

Is there a command to do this?

Thanks,
Jonathan.
Avatar of vinhnl
vinhnl

Hi  Twibblejaway,

I think that you should use a arraylist to store windows open.

ArrayList windowsopen = new ArrayList();

When you open a window, before show it, you add it to arraylist.

windowsopen.Add(form);

When you want to close all windows child, you convert each element to Form Object and close it.

for(int i = 0;i < windowsopen.Count;i++)
   ((System.Windows.Forms.Form)windowsopen[i]).Close();

and remove all from windowsopen

windowsopen.Removeall();

Good luck,
VINHNL


ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial