469,934 Members | 1,540 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,934 developers. It's quick & easy.

Close all child forms

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.
Nov 17 '05 #1
2 4781
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/de...OwnerTopic.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" <Br************@discussions.microsoft.com> wrote in
message news:3E**********************************@microsof t.com...
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.

Nov 17 '05 #2
Thank you very much!

"Tim Wilson" wrote:
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/de...OwnerTopic.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" <Br************@discussions.microsoft.com> wrote in
message news:3E**********************************@microsof t.com...
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.


Nov 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

reply views Thread by clu82 | last post: by
2 posts views Thread by Guy Babbitt | last post: by
1 post views Thread by Martin Douglas | last post: by
reply views Thread by Bruce | last post: by
7 posts views Thread by Alice | last post: by
3 posts views Thread by =?Utf-8?B?RGF2ZVA=?= | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.