I have three forms.
Lets say A, B, C.
Form A opens form B and form B then opens form C.
I have added button Hide all open forms in form C.
Now how do I hide all three forms with this button ?
I know one way is using ShowWindow Api, but I don't want to use Api calls.
Edit : Thanks to 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 form B
C frm = new C();
frm.Owner = this;
frm.Show();
In form C's button click event.
Owner.Owner.Hide();
Owner.Hide();
Hide();
Or thanks to Wim Coenen
foreach (Form var in Application.OpenForms)
{
var.Hide();
}
Thanks.
You just need to access this collection:
Application.OpenForms
Then you just need to iterate over all the items and hide the ones you want (you can check by title for example) or just hide all of them.
Hope it helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With