Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. close winforms childs and main

close winforms childs and main

Scheduled Pinned Locked Moved C#
csharpwinformsquestion
7 Posts 3 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    Ronenb
    wrote on last edited by
    #1

    Hi I have application that is define as MDI, there are several form child once the user press X button, i wish the application to be close and all other windows. at the FromClosing event i add the following code //handle and close the logic layer... foreach (Form frm in this.MdiChildren) { frm.Close(); frm.Dispose(); } Application.Exit(); All childs are closed but the the event FromClosing happen agian, why? i would expect the event of the main form FromClosing will happen only one time. this cause my problems at the logic layer ronen

    L 1 Reply Last reply
    0
    • R Ronenb

      Hi I have application that is define as MDI, there are several form child once the user press X button, i wish the application to be close and all other windows. at the FromClosing event i add the following code //handle and close the logic layer... foreach (Form frm in this.MdiChildren) { frm.Close(); frm.Dispose(); } Application.Exit(); All childs are closed but the the event FromClosing happen agian, why? i would expect the event of the main form FromClosing will happen only one time. this cause my problems at the logic layer ronen

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Ronenb wrote:

      All childs are closed but the the event FromClosing
      happen agian, why?

      Because you called "Application.Exit", which will close all the forms and exit the application. You needn't close all forms manually, exiting the application should be enough and should close all remaining forms (and dispose them) automagically.

      Bastard Programmer from Hell :suss:

      R 1 Reply Last reply
      0
      • L Lost User

        Ronenb wrote:

        All childs are closed but the the event FromClosing
        happen agian, why?

        Because you called "Application.Exit", which will close all the forms and exit the application. You needn't close all forms manually, exiting the application should be enough and should close all remaining forms (and dispose them) automagically.

        Bastard Programmer from Hell :suss:

        R Offline
        R Offline
        Ronenb
        wrote on last edited by
        #3

        in case i will remove closing the child manully, once i click close "X", each time child window will be closed i need to press X button accurding the number of child windows that are opend what am i'm missing? what is the correct process to close MDI application? thanks ronen

        L 1 Reply Last reply
        0
        • R Ronenb

          in case i will remove closing the child manully, once i click close "X", each time child window will be closed i need to press X button accurding the number of child windows that are opend what am i'm missing? what is the correct process to close MDI application? thanks ronen

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          There are TWO X-es on a MDI-form if you have the children maximized. If you want to close the application, you close the mainform. That's how things work in Windows, and across all other MDI-applications. If you close one of the child-windows by using it's X, then you are merely closing that particular document of the "Multiple Document Interface". Likewise, Ctrl-F4 would close a child-document, Alt-F4 would close the application.

          Ronenb wrote:

          what is the correct process to close MDI application?

          Application.Exit from code, the X topright of the mainform or Alt-F4 from user-input.

          Bastard Programmer from Hell :suss:

          R 1 Reply Last reply
          0
          • L Lost User

            There are TWO X-es on a MDI-form if you have the children maximized. If you want to close the application, you close the mainform. That's how things work in Windows, and across all other MDI-applications. If you close one of the child-windows by using it's X, then you are merely closing that particular document of the "Multiple Document Interface". Likewise, Ctrl-F4 would close a child-document, Alt-F4 would close the application.

            Ronenb wrote:

            what is the correct process to close MDI application?

            Application.Exit from code, the X topright of the mainform or Alt-F4 from user-input.

            Bastard Programmer from Hell :suss:

            R Offline
            R Offline
            Ronenb
            wrote on last edited by
            #5

            i'm trying to closing the app by the mainform X :), not the child form X the status is when i press the mainform X, a child win is closed, each click close child form till all childs are closed, last click on X close the app once no child exist any advice?

            L B 2 Replies Last reply
            0
            • R Ronenb

              i'm trying to closing the app by the mainform X :), not the child form X the status is when i press the mainform X, a child win is closed, each click close child form till all childs are closed, last click on X close the app once no child exist any advice?

              L Offline
              L Offline
              Lost User
              wrote on last edited by
              #6

              Ronenb wrote:

              any advice?

              Yes. Post the code from the children's OnCloseForm handler. Start a new project, add this code;

              namespace WindowsFormsApplication15
              {
              public partial class Form1 : Form
              {
              public Form1()
              {
              InitializeComponent();
              this.IsMdiContainer = true;

                      new Form() { MdiParent = this, Visible = true };
                      new Form() { MdiParent = this, Visible = true };
                  }
              }
              

              }

              That'll display two documents within a MDI-parent. App will close on X, unless you have some custom code somewhere.

              Bastard Programmer from Hell :suss:

              1 Reply Last reply
              0
              • R Ronenb

                i'm trying to closing the app by the mainform X :), not the child form X the status is when i press the mainform X, a child win is closed, each click close child form till all childs are closed, last click on X close the app once no child exist any advice?

                B Offline
                B Offline
                Big Daddy Farang
                wrote on last edited by
                #7

                Do any of the child forms have FormClosing(..) handlers? If so check them to see if they might be doing anything that's interfering, such as setting e.Cancel to true. You might also try stepping through the main form's closing handler with the debugger if you haven't done that already.

                BDF I often make very large prints from unexposed film, and every one of them turns out to be a picture of myself as I once dreamed I would be. -- BillWoodruff

                1 Reply Last reply
                0
                Reply
                • Reply as topic
                Log in to reply
                • Oldest to Newest
                • Newest to Oldest
                • Most Votes


                • Login

                • Don't have an account? Register

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • World
                • Users
                • Groups