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
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Markandeyulu SPosted Mar 24, 2008, 3:08 AM
AlanPosted Mar 23, 2008, 11:58 AM
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.