Know when an mdi child closes?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • SStory

    Know when an mdi child closes?

    How can the MDI parent form know when an MDI child closes?

    I need to know when the last one closes because I have something on the MDI
    form that I need to clear out when all children are closed...

    Thanks,

    Shane


  • Kerem Gümrükcü

    #2
    Re: Know when an mdi child closes?

    Hi,

    there are more ways to solve this.
    you can use a global counter and increment or decrement it while opening and
    closing forms.
    but there is a build in counter in the MDIParent window. use these to get
    the mdiclient forms count:

    [ParentFormName].MdiChildren.Le ngth

    Use a callback from mdichilds or something like that to inform the parent
    window.
    this can be done with subclassing or eventhandlers for the windows. its up
    to you...

    check this for more information:



    This is the best solution without any workaround...

    Best regards

    Kerem Gümrükcü


    Comment

    • SStory

      #3
      Re: Know when an mdi child closes?

      Yes... well I am need notification. There is no MdiChildClosed event
      There is the MdiChildActivat ed.....
      bummer...

      Guess I will have to have the child call the parent someway to say closing
      and then see if any children are open.

      Shane
      "Kerem Gümrükcü" <kareem114@hotm ail.com> wrote in message
      news:ujJ$ofmgEH A.644@tk2msftng p13.phx.gbl...[color=blue]
      > Hi,
      >
      > there are more ways to solve this.
      > you can use a global counter and increment or decrement it while opening[/color]
      and[color=blue]
      > closing forms.
      > but there is a build in counter in the MDIParent window. use these to get
      > the mdiclient forms count:
      >
      > [ParentFormName].MdiChildren.Le ngth
      >
      > Use a callback from mdichilds or something like that to inform the parent
      > window.
      > this can be done with subclassing or eventhandlers for the windows. its up
      > to you...
      >
      > check this for more information:
      >
      >[/color]
      http://msdn.microsoft.com/library/de...ldrenTopic.asp[color=blue]
      >
      > This is the best solution without any workaround...
      >
      > Best regards
      >
      > Kerem Gümrükcü
      >
      >[/color]


      Comment

      • Cor Ligthert

        #4
        Re: Know when an mdi child closes?

        Shane,

        I did not try this, however I would try it raising a public event in my
        clossing event and catch that in my mainMDI form, when I had this to solve.

        I hope this helps a little bit.

        Cor
        [color=blue]
        > Yes... well I am need notification. There is no MdiChildClosed event
        > There is the MdiChildActivat ed.....
        > bummer...
        >
        > Guess I will have to have the child call the parent someway to say closing
        > and then see if any children are open.
        >
        > Shane
        > "Kerem Gümrükcü" <kareem114@hotm ail.com> wrote in message
        > news:ujJ$ofmgEH A.644@tk2msftng p13.phx.gbl...[color=green]
        > > Hi,
        > >
        > > there are more ways to solve this.
        > > you can use a global counter and increment or decrement it while opening[/color]
        > and[color=green]
        > > closing forms.
        > > but there is a build in counter in the MDIParent window. use these to[/color][/color]
        get[color=blue][color=green]
        > > the mdiclient forms count:
        > >
        > > [ParentFormName].MdiChildren.Le ngth
        > >
        > > Use a callback from mdichilds or something like that to inform the[/color][/color]
        parent[color=blue][color=green]
        > > window.
        > > this can be done with subclassing or eventhandlers for the windows. its[/color][/color]
        up[color=blue][color=green]
        > > to you...
        > >
        > > check this for more information:
        > >
        > >[/color]
        >[/color]
        http://msdn.microsoft.com/library/de...ldrenTopic.asp[color=blue][color=green]
        > >
        > > This is the best solution without any workaround...
        > >
        > > Best regards
        > >
        > > Kerem Gümrükcü
        > >
        > >[/color]
        >
        >[/color]


        Comment

        • Jens Christian Mikkelsen

          #5
          Re: Know when an mdi child closes?

          "SStory" <TheStorys@TAKE OUTTHISSPAMBUST ERsofthome.net> skrev i en meddelelse
          news:OEgNbMogEH A.3264@tk2msftn gp13.phx.gbl...[color=blue]
          > Yes... well I am need notification. There is no MdiChildClosed event
          > There is the MdiChildActivat ed.....
          > bummer...[/color]

          Take a closer look at the docs on the MdiChildActivat e event:

          "Occurs when a multiple document interface (MDI) child form is activated or
          closed within an MDI application."

          Source:


          So you DO get an event, when the MDI child closes.

          /Jens


          --
          Jens Christian Mikkelsen
          Student of performance, automation, JavaScript, C#, C++ and many other things.



          Comment

          • Herfried K. Wagner [MVP]

            #6
            Re: Know when an mdi child closes?

            * "SStory" <TheStorys@TAKE OUTTHISSPAMBUST ERsofthome.net> scripsit:[color=blue]
            > How can the MDI parent form know when an MDI child closes?[/color]

            See (complete thread):

            <URL:http://www.google.de/groups?threadm= %23YhPW6KSEHA.1 388%40TK2MSFTNG P09.phx.gbl>

            --
            Herfried K. Wagner [MVP]
            <URL:http://dotnet.mvps.org/>

            Comment

            • Jay B. Harlow [MVP - Outlook]

              #7
              Re: Know when an mdi child closes?

              Shane,
              I would use the techniques mentioned in the Thread that Herfried showed.

              The sample Herfried mentions assuming that there will only be one instance
              of the child, if you can have multiple instances of the child forms, instead
              of m_child As Form2 you may want to keep a collection of children...

              As Jens pointed out, I think the MdiChildActivat ed event will also tell you
              what you want.

              Hope this helps
              Jay

              "SStory" <TheStorys@TAKE OUTTHISSPAMBUST ERsofthome.net> wrote in message
              news:Ohw90TmgEH A.2764@TK2MSFTN GP11.phx.gbl...[color=blue]
              > How can the MDI parent form know when an MDI child closes?
              >
              > I need to know when the last one closes because I have something on the[/color]
              MDI[color=blue]
              > form that I need to clear out when all children are closed...
              >
              > Thanks,
              >
              > Shane
              >
              >[/color]


              Comment

              • SStory

                #8
                Re: Know when an mdi child closes?

                Hey man--this is good news!! Thanks a bunch I will try it out.
                Most importantly I am needing to know when the last one has closed to clean
                up shared resources.

                Thanks... I will check it out.

                Shane
                "Jens Christian Mikkelsen" <jensmNoSpam@jc mikkelsenNoSpam Please.dk> wrote in
                message news:uIAuSWpgEH A.3612@TK2MSFTN GP12.phx.gbl...[color=blue]
                > "SStory" <TheStorys@TAKE OUTTHISSPAMBUST ERsofthome.net> skrev i en[/color]
                meddelelse[color=blue]
                > news:OEgNbMogEH A.3264@tk2msftn gp13.phx.gbl...[color=green]
                > > Yes... well I am need notification. There is no MdiChildClosed event
                > > There is the MdiChildActivat ed.....
                > > bummer...[/color]
                >
                > Take a closer look at the docs on the MdiChildActivat e event:
                >
                > "Occurs when a multiple document interface (MDI) child form is activated[/color]
                or[color=blue]
                > closed within an MDI application."
                >
                > Source:
                >[/color]
                http://msdn.microsoft.com/library/en...ivateTopic.asp[color=blue]
                >
                > So you DO get an event, when the MDI child closes.
                >
                > /Jens
                >
                >
                > --
                > Jens Christian Mikkelsen
                > http://www.jcmikkelsen.dk
                >
                >[/color]


                Comment

                • SStory

                  #9
                  Re: Know when an mdi child closes?

                  Yeah... it thought about the forms collection but doesn't mdi parent already
                  have a collection? So seems like duplication for nothing and my real issue
                  was being informed of when one closed so I could decide if it were the last
                  one.

                  I think Jens's suggestion may be just what I need and I can check
                  mdichildren count or whatever the mdichild collection is named--I'm not in
                  the IDE right now...

                  Thanks.
                  "Jay B. Harlow [MVP - Outlook]" <Jay_Harlow_MVP @msn.com> wrote in message
                  news:OgqCZAvgEH A.3536@TK2MSFTN GP12.phx.gbl...[color=blue]
                  > Shane,
                  > I would use the techniques mentioned in the Thread that Herfried showed.
                  >
                  > The sample Herfried mentions assuming that there will only be one instance
                  > of the child, if you can have multiple instances of the child forms,[/color]
                  instead[color=blue]
                  > of m_child As Form2 you may want to keep a collection of children...
                  >
                  > As Jens pointed out, I think the MdiChildActivat ed event will also tell[/color]
                  you[color=blue]
                  > what you want.
                  >
                  > Hope this helps
                  > Jay
                  >
                  > "SStory" <TheStorys@TAKE OUTTHISSPAMBUST ERsofthome.net> wrote in message
                  > news:Ohw90TmgEH A.2764@TK2MSFTN GP11.phx.gbl...[color=green]
                  > > How can the MDI parent form know when an MDI child closes?
                  > >
                  > > I need to know when the last one closes because I have something on the[/color]
                  > MDI[color=green]
                  > > form that I need to clear out when all children are closed...
                  > >
                  > > Thanks,
                  > >
                  > > Shane
                  > >
                  > >[/color]
                  >
                  >[/color]


                  Comment

                  • SStory

                    #10
                    Re: Know when an mdi child closes?

                    hmm..

                    Adding a handler to the MDI child that points back to the MDI parent sounds
                    like a good potential.

                    Now when I do this....if also in the MDIchild's close event I put some code,
                    would both execute and which would be first?

                    Thanks,

                    Shane

                    "Herfried K. Wagner [MVP]" <hirf-spam-me-here@gmx.at> wrote in message
                    news:2o8md6F7o5 g3U4@uni-berlin.de...[color=blue]
                    > * "SStory" <TheStorys@TAKE OUTTHISSPAMBUST ERsofthome.net> scripsit:[color=green]
                    > > How can the MDI parent form know when an MDI child closes?[/color]
                    >
                    > See (complete thread):
                    >
                    >[/color]
                    <URL:http://www.google.de/groups?threadm=...TK2MSFTNGP09.p
                    hx.gbl>[color=blue]
                    >
                    > --
                    > Herfried K. Wagner [MVP]
                    > <URL:http://dotnet.mvps.org/>[/color]


                    Comment

                    • Herfried K. Wagner [MVP]

                      #11
                      Re: Know when an mdi child closes?

                      * "SStory" <TheStorys@TAKE OUTTHISSPAMBUST ERsofthome.net> scripsit:[color=blue]
                      > Adding a handler to the MDI child that points back to the MDI parent sounds
                      > like a good potential.
                      >
                      > Now when I do this....if also in the MDIchild's close event I put some code,
                      > would both execute and which would be first?[/color]

                      This depends on which order the event handlers are added. Typically the
                      handler defined in the main form will execute after the event handler
                      defined in the child form.

                      --
                      M S Herfried K. Wagner
                      M V P <URL:http://dotnet.mvps.org/>
                      V B <URL:http://dotnet.mvps.org/dotnet/faqs/>

                      Comment

                      Working...