Closing all windows and returning to main menu

Posted on 2006-03-26
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?

Question by:twibblejaway
    LVL 8

    Expert Comment

    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.


    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++)

    and remove all from windowsopen


    Good luck,

    LVL 85

    Accepted Solution

    If you are working in C# 2005, then use the Application.OpenForms() collection:

    If you are using an Mdi approach, then use the MdiChildren() collection:

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

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Looking for New Ways to Advertise?

    Engage with tech pros in our community with native advertising, as a Vendor Expert, and more.

    In one of my recent projects, I was working with IP cameras, I need to take some pictures from the camera and do some processing on it. The first step, was to retrieve the image from camera into Image object. So that it can be displayed or …
    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    779 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

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now