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.
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.
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();
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
}
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.
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