If there are two forms eg. Form1.cs and Form2.cs how do you hide and show them?
so if you want to hide Form2.cs by this.Hide();
and using a command code on form1 what would it be?
Thanks
Hide/Show Forms?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.

AlanRank #669 · 3.6K reputationPosted Mar 23, 2008, 7:58 AM EDT
To hide Form2 from Form1, you need to have a reference to it.
Assuming you're showing Form2 from Form1, I'd save a reference to it in a private field so you can use it from other methods in the Form1 class. For example (all code in Form1):
// add field
private Form2 form2;
// inside the method where you show Form2
form2 = new Form2(); // no need now for a local variable
form2.Show();
// inside another method where you want to hide Form2
if (form2 != null) form2.Hide();
Notice that if you show Form2 modally using f2.ShowDialog(), then you won't be able to hide it from Form1 whose code will effectively be suspended until Form2 is closed by the user.
Markandeyulu S2 reputationPosted Mar 23, 2008, 11:08 PM EDT