Click here to Skip to main content
15,891,951 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have developed a windows based application using VB.NET 2005. It is working perfectly fine. Now the client wants to add an option called "Logout". When this is selected, all the open windows forms should get closed, the MDI form need to get opened with the login form on top of it.

Can anyone please suggest as to what can be done to sort out this matter.

Regards, Sachin
Posted

By "all the forms" I assume you mean any child forms of the MDI parent.

If so this is easy. The child windows are available in a property called MdiChildren[^], this is just an array of Form. Just loop through this array calling each form's Close() methods.

You may need to tidy up any resources you have hanging over, hidden MDI childen aren't disposed when they are closed.
 
Share this answer
 
Add one link button and on click add this code..

C#
Protected void LinkLogOut_click(Object sender, EventArgs e)
{
    foreach(Form fm in Application.OpenForms)
    {
         if(fm.Name !="LoginForm")
         {
             fm.close();
         }
    }
}


hope this helps..
 
Share this answer
 
It's very simple you can make a method to close all the forms and at the end just show your Login form.Example :
VB
Private Sub CloseAllForms()
   Form1.Close()
   Form2.Close()
   Form3.Close()
   'Write all the forms you used in your application no matter form is Open or Close 
   'If any form is open then this method will close that form
   'After closing all forms just show your Login Form
   FrmLogin.Show()
End Sub

Call above method on LogOut Button.

-MKB :)
 
Share this answer
 
Comments
Keith Barrow 12-Dec-11 11:15am    
I haven't voted, so please don't assume it was me, I only downvote if the advice is really bad/malicious/trolling.
The requirement is to close child forms of an MDI application, so your code won't work under *normal* circumstances. With MDI, the intention is to allow the user to use multiple documents (e.g. Word has an MDI) in this case it is impossible from a practical perspective to know the Instances open at compile-time. The coder must therefor loop the list of child instances to close.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900