I have three forms.
Suppose A, B, C.
Form A opens Form B and Form B then opens Form C.
I added a Hide all open forms button in C.
Now, how can I hide all three forms with this button?
I know that one way uses ShowWindow Api, but I don't want to use Api calls.
Edit: Thanks SoMoS .
for (int i = Application.OpenForms.Count - 1; i >= 0; i += -1) { if (!object.ReferenceEquals(Application.OpenForms[i], this)) { Application.OpenForms[i].Hide(); } } this.Hide();
or
In form A (thanks to ho1 )
B frm = new B(); frm.Owner = this; frm.Show();
In the form of B
C frm = new C(); frm.Owner = this; frm.Show();
In the button click event of form C.
Owner.Owner.Hide(); Owner.Hide(); Hide();
Or thanks to Wim Cohenen
foreach (Form var in Application.OpenForms) { var.Hide(); }
Thanks.
c #
Searock
source share