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.
Syncfusion Feedback

Closing all MDI forms

Thread ID:

Created:

Updated:

Platform:

Replies:

37172 Nov 16,2005 09:39 PM UTC Nov 18,2005 07:04 AM UTC Windows Forms 3
loading
Tags: Tools
Jim
Asked On November 16, 2005 09:39 PM UTC

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

Jim
Replied On 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

Mano J [Syncfusion]
Replied On 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

CONFIRMATION

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.

Warning Icon 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.Close Icon

;