I'm using WinForms
. I want to close all of the forms except my main form called Form1
. I noticed that my main Form is index 0, so i was wondering if i could do something like, close all the forms except of index 0. How can i do this? This is what i have so far.
List<Form> openForms = new List<Form>();
foreach (Form f in Application.OpenForms)
{
openForms.Add(f);
int mainFormIndex = openForms.IndexOf(0);
Console.WriteLine(": " + mainFormIndex);
if(mainFormIndex != 0)
{
this.Owner.Close();
}
else
{
this.Close();
}
}
}