Click here to Skip to main content
15,893,381 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I'm programming c# GUI and I have 2 forms.
Form1 is my main form, and it has a button to open form2.
When the button in form1 is being clicked, I hide form1, create a new object of form2 and show form2.

I have a back button in form2. I want the behavior of this button to close form2, and show again the hidden form1.

How can I do it?

Thanks
Posted
Comments
Philippe Mori 17-Dec-11 19:14pm    
Generally, it is not a good idea to hide the main form except if you replace the default logic... If fact, it not a great idea anyway as depending on the OS, it will cause buttons to move in the Taskbar if multiple applications are opened.

Could you simply use Form.ShowDialog Method [^]. The back button on form 2 would close the form2 so the control would automatically get back to form1.

If needed, the form 1 could be hidden before the ShowDialogCall using for example: http://msdn.microsoft.com/en-us/library/system.windows.forms.control.hide.aspx[^]
 
Share this answer
 
Comments
Uday P.Singh 17-Dec-11 15:28pm    
5ed :)
Wendelius 18-Dec-11 3:33am    
Thanks.
you can go with the Mika's answer or you can do this:
on back button of form2 write:

C#
private void button1_Click(object sender, EventArgs e)
        {
            this.Close();
            Form1 frm = new Form1();
            frm.Show();//or
//frm.ShowDialog();

        }


hope it helps :)
 
Share this answer
 
v2
Comments
Wendelius 18-Dec-11 3:35am    
Yep, that's also a possibility. 5'd

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900