views:

197

answers:

4

Hey

I made 2 forms in c sharp visual studio. How can I make one form invisible and another visible (Have done this in visual basic only before)

I guess Syntax should be similar.

+3  A: 

Use the Form.Visible property, or the Form.Show() method.

CesarGon
@downvoter: Care to explain why?
CesarGon
A: 

Use the property Visible of the class Form.

Nestor
+3  A: 

To hide and show a form, use the Form.Visible property:

Form.Visible = true;
Form.Visible = false;

There's also methods that do the same thing (these are designed to be used with the MethodInvoker delegate):

Form.Show();
Form.Hide();
thecoop
I still have troubles getting this to work.Here is what I tried: Form2.ActiveForm.Show(); //Form2.Hide(); Form2.ActiveForm.Activate(); Form2.ActiveForm.Visible = true;I don't know why, but I need to use ActiveForm method or I get errors.Any suggestions ?
raimicq
+1  A: 

If I remember correctly, VB.NET will pre-create the forms for you, and you only have to call Show(). In C#, you will have to create all but the MainForm.

// in a buttonClick on Form1
Form2 f2 = new Form2();
f2.Show();

This will create a new instance each time you click the button.

Henk Holterman
This helped!Thanks
raimicq