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. Image for the cookie policy date
close icon

Closing all MDI forms

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--; } }

3 Replies

MJ Mano J Syncfusion Team November 17, 2005 04:30 AM UTC

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


JI Jim November 17, 2005 04:41 PM UTC

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


MJ Mano J Syncfusion Team November 18, 2005 07:04 AM UTC

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

Loader.
Live Chat Icon For mobile
Up arrow icon