We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

Closing all MDI forms

Thread ID:





37172 Nov 16,2005 04:39 PM Nov 18,2005 02:04 AM Windows Forms 3
Tags: Tools
Asked On November 16, 2005 04:39 PM

Given the fact that Syncfusion creates phantom MDI forms, what is the proper way to close all MDI forms from code? Below code generates exception. Foreach doesn''t work either (just because you can''t delete something from collection while iterating over it). public void CloseAllMDIForms() { for (int x =0; x < mainWindow.MdiChildren.Length; x++) { Form child = (Form)mainWindow.MdiChildren[x]; child.Close(); x--; } }

Mano J [Syncfusion]
Replied On November 16, 2005 11:30 PM

Hi Jim, You should check for the specific tabGroup and handle the mdiTabPanel to close all the forms in the tabGroup. Please refer to the coding snippet below. // Handle child form''s closing event child.Closing +=new CancelEventHandler(this.MdiChildFormClosed); private void MdiChildFormClosed (object sender, CancelEventArgs arg) { if (flag == 0) { Form2 form = sender as Form2; // check for the TabGroup in which it is present foreach(TabPageAdv page in this.tabbedMDIManager.GetTabHostFromForm(form).MDITabPanel.TabPages) { // the tabpage''s Tag stores the MDI form associated with it Form2 temp = page.Tag as Form2; if (form == temp) { flag = 1; this.CloseAllForms(this.tabbedMDIManager.GetTabHostFromForm(form).MDITabPanel); break; } } } flag = 0; } private void CloseAllForms(MDITabPanel mdiTabpanel) { foreach(TabPageAdv page in mdiTabpanel.TabPages) { ((Form2)page.Tag).Close(); } } Please refer to the sample attached below that illustrated this completely and let me know if you have any questions. Regards, Mano CloseAllTabs.zip

Replied On November 17, 2005 11:41 AM

Mano, I confess I don''t entirely understand the object hierarchy with the TabbedMDIManager class, but I fooled around with your code a bit and came up with this: public void CloseAllMDIForms() { // we can''t just iterate through mdi children collection and close // because Syncfusion creates phantom MDI forms, so this is necessary instead foreach (TabHost host in mainWindow.tabbedMDIManager.TabGroupHosts) { TabPageAdvCollection pages = host.MDITabPanel.TabPages; foreach (TabPageAdv page in pages) ((Form)page.Tag).Close(); } } This appears to work. I''m not too crazy about the phantom MDI forms, perhaps you can consider changing your approach to that somehow in the future, if that is technically possible. Failing that, it would be nice for you to simply provide a CloseAllMDIForms() function. Thanks, Jim

Mano J [Syncfusion]
Replied On November 18, 2005 02:04 AM

Hi Jim, Thanks for the update.We will consider this as a feature request and try to implement it in our feature releases. Regards, Mano


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.