mdi child forms not closing in the right order

R

Rob

Hi all, I am just starting to write my first mdi app and get the
feeling that if you hit the 'X' in top-right mdi form to close it, the
order of events is as follows: all mdi child forms first get the
'closing' event, THEN they all get the 'closed' event. If this is true
then I don't know of any mdi app that behaves that way. I expect each
mdi child form to get the 'closing' AND 'closed' event before the next
mdi child gets both of those events. Bear in mind, that I am just
starting with this, so perhaps I am missing something obvious.

The problem is that if I put code in the 'closing' event of each child
to prompt user to save: yes, no, cancel, then say for example the user
answers 'yes' to the first child, that child should save and close
completely before the user is prompted to save the next child. I am
finding that all the child windows remain open, until user has
answered all prompts. This seems weird, especially if the user
cancells on say the third child, then the first two child windows
remain open, when in fact they should have been long gone.

Am I missing something? or is there a way to overwrite this behaviour
and close mid child forms in the order that I want. For example
something else that would be nice is if the 'closing' event on the
active form was called before any other form. Since I dissagree with
what appears to be the default behaviour, I'd like to have more
control over this. Can anyone help me find an example on how to do a
custom close of an mdi app.

BTW: I am using C# and what an awesome language, if I may say so. ;-)

Thank You,
Rob.
 
G

Guest

Ok, you want more control eh

On the MDI parent, you use the closing event to trigger some subs

You would go though the parents mdichildren property and the children forms are in order as they were added as mdi children to the parent.

You would create a standard interface and all child forms would implement this interface. The interface would have something like a getchanges, close, save subs

You would cast the childform (from looping though the mdichildren) to the interface and invoke the getchanges to know if there is any changes if true then invoke save and then close

Simple as apple pie.
 
R

Rob

Joe Fuentes said:
Ok, you want more control eh?

On the MDI parent, you use the closing event to trigger some subs.

You would go though the parents mdichildren property and the children forms are in order as they were added as mdi children to the parent.

You would create a standard interface and all child forms would implement this interface. The interface would have something like a getchanges, close, save subs.

You would cast the childform (from looping though the mdichildren) to the interface and invoke the getchanges to know if there is any changes if true then invoke save and then close.

Simple as apple pie.


Mmmm, apple pie. Thanks Joe, much appreciated, but I'm still thinking
of alternatives on this one. If I understand you correctly you are
saying that I should take my code out of the child 'closing' events
and just handle everything at the topmost mdi level, questioning each
child in the order I want. This is cool, but I forgot to mention that
I am writing a bit of a mdi framework/template, which I intend for
other developers to use, so ideally I'd like to somehow overwrite the
default .net framework behaviour, such that other developers
inheriting from my MdiForm and MdiChild classes can still implement
the 'closing' and 'closed' events in the child forms without being
aware that the order in which those events are called has changed.
Something tells me I'm going to have to extend the WndProc method and
capture the SC_CLOSE syscommand, which is what I am experimenting with
now. I would preffer to avoid using Win API and do a more pure .net
solution, so if you or anyone has any alternatives, please post here.

Thanks again for your reply though.

Cheers,
Rob.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top