Wnidows forms Closing
In my application, Iam not used mdi concept. So in my application has different forms. So, I want to close all the forms which is opened before opening the form.
Hi, I not able to close the form from another from.
please give me a solution For my problem.
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

Master BillaRank #2,229 · 630 reputationPosted Sep 26, 2009, 7:18 AM EDT
You can close the all opened form by this code
private void CloseAll()
{
FormCollection colection = System.Windows.Forms.Application.OpenForms;
for (int i = 0; i < colection.Count; i++)
{
Form formcommon = colection[i];
formcommon.Close();
}
}
thank you
Roei BarRank #1,271 · 1.4K reputationPosted Sep 26, 2009, 9:34 AM EDT
you need 1 modification:
private void CloseAll() { FormCollection colection = System.Windows.Forms.Application.OpenForms; for (int i = 0; i formcommon is not this) formcommon.Close(); //this will close all forms but the one in focus //and then you can load the new form and close it } }