Close all child forms

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hey, it's me again.
Is there a way to, when closing a form, close also all forms opened inside
this one? I'm not talking about MDI.
Let's say I create and open three forms in Form1. When I close Form1, and
he's not the main form of my app, I want to close all the three forms I
opened.
It would be nice to do that without a Form[] collection so I don't need to
iterate throut it.

Thanks.
 
Thank you very much!

Tim Wilson said:
You can use the "Owner" property of the forms that are created and set this
property to this (or Me) of the form that opened them.
http://msdn.microsoft.com/library/d...rlrfSystemWindowsFormsFormClassOwnerTopic.asp

// ... in Form1

Form2 f2 = new Form2();
f2.Owner = this;

Form3 f3 = new Form3();
f3.Owner = this;

f2.Show();
f3.Show();

--
Tim Wilson
..NET Compact Framework MVP

Bruno Rodrigues said:
Hey, it's me again.
Is there a way to, when closing a form, close also all forms opened inside
this one? I'm not talking about MDI.
Let's say I create and open three forms in Form1. When I close Form1, and
he's not the main form of my app, I want to close all the three forms I
opened.
It would be nice to do that without a Form[] collection so I don't need to
iterate throut it.

Thanks.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top