Windows Develop Bookmark and Share   
 index > Windows Forms General > How To force all MDI parent and child forms to close on MDIParent Exit or MDIParent Close
 

How To force all MDI parent and child forms to close on MDIParent Exit or MDIParent Close

To force all MDI parent and child forms to close on MDIParent Exit or MDIParent Close

Hi,
How To force all MDI parent and child forms to close on MDIParent Exit or MDIParent Close?
when i am trying to exit/close MDI parent it raises formclosing event for MDI childs.
with this it shows save filedialog for each mdi child and at the end one more save file dialog from MDI parent.

My query is, how to close all MDI childs at once on MDI parent Exit like Visual Studio does with one save file dialog with multiple file names.

please help me.
  • Edited byManasMSDN Monday, August 03, 2009 5:39 PMtitle
  • Moved byTaylorMichaelLMVPMonday, August 03, 2009 6:01 PMWinforms related (From:.NET Base Class Library)
  • Edited byManasMSDN Monday, August 03, 2009 7:27 PMedited dessciption
  •  
ManasMSDN  Monday, August 03, 2009 5:39 PM
You can iterate the list of all open child forms and if it is more than 1, then give user an option of "Save All" in a dialog box. If the user selects "Save All", you can loop through the list of all open forms and save the file/form via code, rather showing the Save file dialog.
guptashail  Tuesday, August 04, 2009 10:02 PM
hi,

i need Visual Studio kind of behavior.
ManasMSDN  Wednesday, August 05, 2009 10:32 PM

Hi

You can check the status of each child for its saved state and if it is unsaved add it to some list. after completion, you can show the list of unsaved files in a dialog with the file names under which they will be saved. if the file is untitled then either you can ask for file name or provide a default one.


Happy Debugging Bimal
Bimal.net  Thursday, August 06, 2009 4:45 AM
Hi,
You need to create a event handler for parent form .when the parent form closing event you fire the event and close all other child form.
i hope it will help you...
Best Regards, C.Gnanadurai
Gnanadurai  Thursday, August 06, 2009 7:51 AM
Hi,

that's what Parent Form Closing event is doing.
ManasMSDN  Friday, August 07, 2009 4:32 PM
hi,

did u get my point , if so then how abt visual studio is working in different way.

check,

1.if i need to close manually MDI childs i should get Save File dialog for each.
2.if i close Parent -MDI Parent then all MDI child names should appear in one Save File Dialog.

it is just like Visual Studio.........behavior i need
ManasMSDN  Friday, August 07, 2009 4:37 PM
To force all MDI parent and child forms to close on MDIParent Exit or MDIParent Close

Hi,
How To force all MDI parent and child forms to close on MDIParent Exit or MDIParent Close?
when i am trying to exit/close MDI parent it raises formclosing event for MDI childs.
with this it shows save filedialog for each mdi child and at the end one more save file dialog from MDI parent.

My query is, how to close all MDI childs at once on MDI parent Exit like Visual Studio does with one save file dialog with multiple file names.

please help me.



That is how the MdiParent/Child works.
It is supposed to raise the event on the child forms, and vice versa, because of the merged menu systems.

You need to interrogate the "sender" object in the event handlers to see who raised the event. The current form or another one.

Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Friday, August 07, 2009 4:45 PM
Hi,
as u said "You need to interrogate the "sender" object in the event handlers to see who raised the event. The current form or
another one"

When ever MDIParent is Closed via , FormClose or FormExit its going to raise MDIChild FormClosing Event.

then if i check 'sender' object obviously will show MDIChild as current event caller form

please help me with solution.
ManasMSDN  Friday, August 07, 2009 4:58 PM
What you ask requires a little bit of work.
Employ Object Oriented Programming techinique number one.
Delegation. Delegate, or assign the responsibility of file management to a dedicated class.
It should maintain a list of all open files.

Create the same object instance of this type to manage all opening and closing files in the Parent class.
Pass this same instance to each form as you open them.

When the closing event occurs let this FileManager object generate the user prompts and close the files.

Mark the best replies as answers. "Fooling computers since 1971."
Rudedog2  Friday, August 07, 2009 5:20 PM
Actually, the FormClosingEventArgs parameter being passed on the Form_Closing eventhas a property called CloseReason that can tell us if the form is closing because of the MDI parent form closing.
ie:

If

e.CloseReason = CloseReason.MdiFormClosing Then

'Call the "Exit Application?" code

'If EXIT then call the save the form, otherwise don't try to close

End If

Dunstad  Monday, September 07, 2009 2:47 PM

You can use google to search for other answers

Custom Search

More Threads

• Cyrillic text in .Net application
• ToolstripControlHost custom control not showing up in designer
• Use of WM_CTLCOLORSTATIC in VB.NET? How to do it. Need some help.
• HTML byte stream
• Load tabpage into form
• How to make a usercontrol to act as an container?
• Issue with AxWebbrowser_DocumentCOmplete
• Application Question...
• Capturing Key Events
• how to pass values to another windows application?