Thursday, July 14, 2011 | By: nika perales

How to close all open forms in your MDI Application in VB.Net

I have came across a situation lately where i needed to close all open forms in my MDI Application when a user clicks on the log-off button. Here's how i did it...

Private Sub CloseOpenForms
    
    'create a copy of the collection of current open forms
    'because the Application.OpenForms changes everytime we
    'close an open form
     
    Dim OpenForms As FormCollection = Application.OpenForms

        For Each frm As Form In OpenForms
            'check if current form is our MDI Parent
            'if not then close it, otherwise skip it
            If Not frm.IsMdiContainer Then
               frm.Close()
            End If
        Next
End Sub
 

0 comments:

Post a Comment