Windows Develop Bookmark and Share   
 index > Windows Forms General > Controlling all forms from main program
 

Controlling all forms from main program

Is it possible to do this? Also if there is a button on one form that closes that form and shows another, what kind of code would be required?
  • Moved byTaylorMichaelLMVPMonday, September 28, 2009 1:35 PMWinForms related (From:Visual C# IDE)
  •  
GoodToGo1  Sunday, September 27, 2009 4:40 PM
To control all forms from the main form, keep track of all of the other forms. For example, you could build an array in the main form and store references to new forms there. Then you can loop through the array and close them all (or do whatever else you want to do with them).

To close one form and show another, try something like:

Form new_form = new Form2();
new_form.Show();
this.Close();

Note that this will close the program if the form you are closing is the startup form.

Rod
Rod Stephens  Monday, September 28, 2009 1:44 PM
To control all forms from the main form, keep track of all of the other forms. For example, you could build an array in the main form and store references to new forms there. Then you can loop through the array and close them all (or do whatever else you want to do with them).

To close one form and show another, try something like:

Form new_form = new Form2();
new_form.Show();
this.Close();

Note that this will close the program if the form you are closing is the startup form.

Rod
Rod Stephens  Monday, September 28, 2009 1:44 PM

You can use google to search for other answers

Custom Search

More Threads

• Adding, removing menu items doesn't work
• CPU usage
• How do I update/refresh a .Count in the txtCount ...???
• GUI Drawing
• OnCustomCommand for windows service is not working
• menustrip scrolls out of window
• Need Information about writing a custom SettingsProvider.
• Drawstring- Left Align two strings with different font sizes
• passing global strings??
• Docking MDI Child not redrawing