Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to close all child forms
Message
From
26/11/2006 04:12:43
 
 
To
25/11/2006 16:07:49
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
01172429
Message ID:
01172456
Views:
13
This message has been marked as the solution to the initial question of the thread.
Andrus,

Try this instead:
foreach (Form o in this.MdiChildren)
	o.Close();
~~Bonnie

>I have .net 1.1 WinForms MDI application.
>
>I need to close all MDI child forms.
>I tried
>
>
private void CloseAllForms_Click(object sender, System.EventArgs e){
>
>foreach (Control c in this.Controls) {
>  if (c is MdiClient)
>    ((Form)c).Close();
>  }
>}
>
>but got error
>
>"Unable to cast object of type 'System.Windows.Forms.MdiClient' to type 'System.Windows.Forms.Form'."
>
>Why ?
>
>I also tried c.FindForm().Close();
>but this closes whole application.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform