CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    May 2001
    Location
    paris, France
    Posts
    166

    how to close all forms when closing the application?

    I have a main form on my application and I want to close all forms when I exit the main dialog.
    How can I do that?

    private Sub closeAllForms()
    Dim i as Integer
    for i = 0 to Forms.Count - 1
    If Forms(i).Name <> "Wnd_Main" then
    ' close form(i)??
    End If
    next
    End Sub





  2. #2
    Join Date
    Jun 2001
    Location
    Ireland
    Posts
    56

    Re: how to close all forms when closing the application?

    I'm not to sure what you want to do here!.
    Once the main Form is unloaded all other forms follow suit. Try using your code in the main Forms Unload QueryUnload Event


    private Sub Form_QueryUnload(Cancel as Integer, UnloadMode as Integer)

    Dim i as Integer
    for i = 0 to Forms.Count - 1
    If Forms(i).Name <> me.name then
    'close form
    unload (Forms(i))'(i)?? End If
    next i

    End Sub






    Andrew Lennon (Berlitz)
    Automation Dev Engineer

  3. #3
    Join Date
    Jun 2001
    Location
    Ireland
    Posts
    56

    Re: how to close all forms when closing the application?

    I'm not to sure what you want to do here!.
    Once the main Form is unloaded all other forms follow suit. Try using your code in the main Forms Unload QueryUnload Event


    private Sub Form_QueryUnload(Cancel as Integer, UnloadMode as Integer)

    Dim i as Integer
    for i = 0 to Forms.Count - 1
    If Forms(i).Name <> me.name then
    'close form
    unload (Forms(i))'(i)?? End If
    next i

    End Sub





    Don't forget to Rate !!!!


    Andrew Lennon (Berlitz)
    Automation Dev Engineer

  4. #4
    Join Date
    May 2001
    Location
    paris, France
    Posts
    166

    Re: how to close all forms when closing the application?

    Thanks, it works perfectly



  5. #5
    Join Date
    Apr 2000
    Location
    South Carolina,USA
    Posts
    2,210

    Re: how to close all forms when closing the application?

    Here is but another way to close all forms.
    Set the code u=in the FOrm_Unload event or the QUeryUNload event

    private Sub Form_QueryUnload(Cancel as Integer, UnloadMode as Integer)
    Dim f as Form
    for Each f In Forms
    If f.Name <> me.Name then Unload f
    next f
    End Sub




    Please rate it if it answers the question
    or is useful.
    '
    John G

  6. #6
    Join Date
    Jun 2000
    Posts
    104

    Re: how to close all forms when closing the application?

    Use 'end' in place of any unload statement.It closes all the forms.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured