Can I close several Form at once and leave one open in C #?

0

I have a login and a menu, and in turn the menu has several forms.

What I want to do is that by clicking on close session in the menu, it closes (if any) the other forms and opens the login.

    
asked by Francisco Garcia 13.10.2016 в 04:49
source

4 answers

2

In the menu click event:

foreach (Form frm in Application.OpenForms){
    if (frm != this)    //Cerramos todos los formularios menos el formulario principal que contiene el menú
        frm.Close();
}
LoginForm login = new LoginForm();
login.ShowModal();
    
answered by 13.10.2016 / 09:05
source
2

When you click on Close Session you have to iterate through the open forms of the application and close them, then open the new login form.

FormCollection formulariosApp = Application.OpenForms;
foreach (Form f in formulariosApp ){
    //tus acciones
}
    
answered by 13.10.2016 в 08:37
0

The menu from where the session closes should have an event. You should subscribe to this event from the class that controls the life cycle of all the windows and that way you could close the windows by calling the Close method on each form. Then you should instantiate the login form and display it on the screen. Upload the relevant code so we can help you more concretely.

    
answered by 13.10.2016 в 05:59
0

Just as lyrqs said ( link )

FormCollection formulariosApp = Application.OpenForms;
foreach (Form f in formulariosApp ){
   if (f.Name != "frmLogin") {
       f.close();
   }
}

I'm not sure if it's:

f.close();

or

f.hide();

I hope you serve

    
answered by 13.10.2016 в 09:20