Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Closing One Form From Another Form?

Tags:

c#

winforms

I have a little application that creates alerts whenever a change to a database is made. I have a few options in the alert form that pops up.
One of the options opens another form (a child form) asking the user for further information.

When the child form gets the necessary information from the user, I want it to close as well as the parent form. So far, I only know how to close the child form, but not the parent form.

Parent form > Opens child form
Child gathers information > User clicks ok in child > child closes, parent closes

^this is what I want

I just don't have the brain power to think about how to communicate across forms to accomplish closing the parent form.

Any help would be much appreciated. Actually, it would be super appreciated. If I could learn how to make my forms communicate with each other, I could really do a lot of damage (in a good way 8D ).

like image 723
sooprise Avatar asked Jun 25 '10 19:06

sooprise


1 Answers

In the parent form, you can do something like this:

ChildForm f = new ChildForm();
f.FormClosed += (o,e) => this.Close();
f.Show();
like image 130
BFree Avatar answered Sep 19 '22 20:09

BFree