Return to the main Form, and close the others, from a form that has other forms opened (C#)? -
my problem it´s have form1, opens form2, , opens form, want make button on last form returns main form , closes other.
here´s how programmed forms openings:
form2 popup= new form2(); this.hide(); popup.showdialog(); this.show();
and did same other form, tried doing this:
form1 main= new form1(); this.close(); main.show();
but leaves other forms opened.
thanks!
you can list of open forms in application using application.openforms
. can loop through them , close ones don't want. this:
foreach (form f in application.openforms) { if (f.name != this.name) f.close(); } form1 main= new form1(); this.close(); main.show();
i have no means test code right now, can close current form others in loop, code can reduced to:
foreach (form f in application.openforms) { f.close(); } form1 main= new form1(); main.show();