How to hide MDI children instead of closing them?

J

John

Hi,

I have an MDI application. The MDI children are instantiated when the
form loads and the user has the ability to show them or to hide them.
I trap the Closing event on the children and set e.Hide = true and
then call Hide() to hide the form.

The problem is when the application needs to exit. When the user
clicks the X on the MDI parent the Closing event is fired on all the
children *BEFORE* it's fired for the parent. The children cancel the
close so the application doesn't exit.

What's the right way to make this work?

Thanks,
John
 
G

Gary Milton

Hi John,

Putting 'Application.Exit()' in the Closing event of the MDI form should do
the trick.

HTH,
Gary
 
J

John

Thanks for your reply.

The Closing event in the parent form never gets called if any of the
children forms sets e.Cancel = true.

Am I missing something?

Thanks,
John
 
J

Josip Medved

The problem is when the application needs to exit. When the user
clicks the X on the MDI parent the Closing event is fired on all the
children *BEFORE* it's fired for the parent. The children cancel the
close so the application doesn't exit.


MSDN library - Closing event:
"To force all MDI parent and child forms to close, set the
System.Windows.Forms.ClosingEventArgs.Cancel property to false in
the MDI parent form."
 
Y

Ying-Shen Yu[MSFT]

Have you resolved this problem using the suggestions from the community
members, John?
Please feel free to reply this thread to let me know, if you still have
problem on it.
Thanks!

Best regards,

Ying-Shen Yu [MSFT]
Microsoft community Support
Get Secure! - www.microsoft.com/security

This posting is provided "AS IS" with no warranties and confers no rights.
This mail should not be replied directly, please remove the word "online"
before sending mail.
 

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