We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

Closing all windows and returning to main menu

twibblejaway
twibblejaway asked
on
Medium Priority
209 Views
Last Modified: 2010-04-16
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.
Comment
Watch Question

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


High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.