[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Closing all windows and returning to main menu

Posted on 2006-03-26
2
Medium Priority
?
195 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.
0
Comment
Question by:twibblejaway
2 Comments
 
LVL 8

Expert Comment

by:vinhnl
ID: 16296683
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


0
 
LVL 86

Accepted Solution

by:
Mike Tomlinson earned 1500 total points
ID: 16296720
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.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article introduced a TextBox that supports transparent background.   Introduction TextBox is the most widely used control component in GUI design. Most GUI controls do not support transparent background and more or less do not have the…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …

873 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question