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.
twibblejawayAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

vinhnlCommented:
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


Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
If you are working in C# 2005, then use the Application.OpenForms() collection:
http://msdn2.microsoft.com/en-us/library/system.windows.forms.application.openforms(VS.80).aspx

If you are using an Mdi approach, then use the MdiChildren() collection:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemWindowsFormsFormClassMdiChildrenTopic.asp

Otherwise, you need to manually track your open windows as vinhnl suggests.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.