closing MDI Application with a button

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • painkiller
    New Member
    • Nov 2007
    • 17

    closing MDI Application with a button

    hi,

    im developing a mdi application and want to close this application and all its child forms using a button but im not sure how to do it. Please note that this button is NOT in parent form but in one of the child form. here is my sample code. is it correct way to do it??

    [CODE=vbnet]Private Sub btnCancel_Click (ByVal sender As System.Object, ByVal e As System.EventArg s) Handles btnCancel.Click
    Dim frm As New frmMain 'this is the parent form
    For Each temp As Form In frm.MdiChildren
    temp.Dispose()
    Next
    Application.Exi t()
    End Sub [/CODE]

    im using .NET 1.1 and VS 2003
    Last edited by debasisdas; Nov 16 '07, 07:40 AM. Reason: Formatted using code=vbnet tags.
  • Plater
    Recognized Expert Expert
    • Apr 2007
    • 7872

    #2
    Can you get away with doing:
    [code=vbnet]
    Me.Parent.Close
    [/code]
    ???

    Comment

    • painkiller
      New Member
      • Nov 2007
      • 17

      #3
      yes i can but i dont think it will close all other child forms. what u say???

      Comment

      • Shashi Sadasivan
        Recognized Expert Top Contributor
        • Aug 2007
        • 1435

        #4
        If you close the parent form (which is MDI type), the child forms attached to it will close too.
        If you want to exit the application
        Application.Exi t does the trick, however you will need to find the equivalent of it in vb .net

        Comment

        • painkiller
          New Member
          • Nov 2007
          • 17

          #5
          Application.Exi t actually works in vb.net

          so i guess its just Application.Exi t and all other child forms will be closed automatically (both hidden and not-hidden) ???

          Comment

          • Shashi Sadasivan
            Recognized Expert Top Contributor
            • Aug 2007
            • 1435

            #6
            Originally posted by painkiller
            Application.Exi t actually works in vb.net

            so i guess its just Application.Exi t and all other child forms will be closed automatically (both hidden and not-hidden) ???
            Yes, Application.Exi t will shut down the entire application thread. (and its children)

            Comment

            • painkiller
              New Member
              • Nov 2007
              • 17

              #7
              thanks for all the replys

              Comment

              • hemantpatil
                New Member
                • Nov 2007
                • 8

                #8
                hi
                you use following code
                Form[] charr= this.MdiChildre n;

                //For each child form set the window state to Maximized
                foreach (Form chform in charr)
                chform.Dispose( );

                Comment

                Working...