469,356 Members | 2,013 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

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
Nov 21 '05 #1
10 6815
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.Length

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:

http://msdn.microsoft.com/library/de...ldrenTopic.asp

This is the best solution without any workaround...

Best regards

Kerem Gümrükcü
Nov 21 '05 #2
Yes... well I am need notification. There is no MdiChildClosed event
There is the MdiChildActivated.....
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ü" <ka*******@hotmail.com> wrote in message
news:uj*************@tk2msftngp13.phx.gbl...
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.Length

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:

http://msdn.microsoft.com/library/de...ldrenTopic.asp
This is the best solution without any workaround...

Best regards

Kerem Gümrükcü

Nov 21 '05 #3
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
Yes... well I am need notification. There is no MdiChildClosed event
There is the MdiChildActivated.....
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ü" <ka*******@hotmail.com> wrote in message
news:uj*************@tk2msftngp13.phx.gbl...
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.Length

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:

http://msdn.microsoft.com/library/de...ldrenTopic.asp

This is the best solution without any workaround...

Best regards

Kerem Gümrükcü


Nov 21 '05 #4
"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> skrev i en meddelelse
news:OE**************@tk2msftngp13.phx.gbl...
Yes... well I am need notification. There is no MdiChildClosed event
There is the MdiChildActivated.....
bummer...


Take a closer look at the docs on the MdiChildActivate event:

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

Source:
http://msdn.microsoft.com/library/en...ivateTopic.asp

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

/Jens
--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk
Nov 21 '05 #5
* "SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> scripsit:
How can the MDI parent form know when an MDI child closes?


See (complete thread):

<URL:http://www.google.de/groups?threadm=%23YhPW6KSEHA.1388%40TK2MSFTNGP09.p hx.gbl>

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>
Nov 21 '05 #6
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 MdiChildActivated event will also tell you
what you want.

Hope this helps
Jay

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
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

Nov 21 '05 #7
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" <je*********@jcmikkelsenNoSpamPlease.dk> wrote in
message news:uI**************@TK2MSFTNGP12.phx.gbl...
"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> skrev i en meddelelse news:OE**************@tk2msftngp13.phx.gbl...
Yes... well I am need notification. There is no MdiChildClosed event
There is the MdiChildActivated.....
bummer...
Take a closer look at the docs on the MdiChildActivate event:

"Occurs when a multiple document interface (MDI) child form is activated

or closed within an MDI application."

Source:
http://msdn.microsoft.com/library/en...ivateTopic.asp
So you DO get an event, when the MDI child closes.

/Jens
--
Jens Christian Mikkelsen
http://www.jcmikkelsen.dk

Nov 21 '05 #8
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]" <Ja************@msn.com> wrote in message
news:Og**************@TK2MSFTNGP12.phx.gbl...
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 MdiChildActivated event will also tell you what you want.

Hope this helps
Jay

"SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> wrote in message
news:Oh**************@TK2MSFTNGP11.phx.gbl...
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


Nov 21 '05 #9
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]" <hi***************@gmx.at> wrote in message
news:2o************@uni-berlin.de...
* "SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> scripsit:
How can the MDI parent form know when an MDI child closes?
See (complete thread):

<URL:http://www.google.de/groups?threadm=...TK2MSFTNGP09.p
hx.gbl>
--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #10
* "SStory" <Th*******@TAKEOUTTHISSPAMBUSTERsofthome.net> scripsit:
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?


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/>
Nov 21 '05 #11

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by John Dalberg | last post: by
1 post views Thread by SamSpade | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.