Click here to Skip to main content
15,885,278 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Guys.
I have two form, in form1 i have a button to do:
1.close this form
2.open form2


i wrote this code but i did not work(jus opened the form2)
C#
Form2 frm2 = new Form2();
            frm2.ShowDialog();
            this.Close();


how can i do it?
Posted
Comments
Daniele Rota Nodari 27-Nov-12 5:15am    
Your code does not work as expected because ShowDialog makes frm2 modal, preventing the Close call to be reached until frm2 gets closed.
The solution provided by NeelmaniN work around this behavior by displaying frm2 as non-modal.
Beware that as being non-modal, other forms inside the same application can be used while frm2 being still shown.
siasalar 27-Nov-12 5:41am    
tnx alot for your responsibility. and your obvious answer.

1 solution

Form2 frm2 = new Form2();
frm2.Show();
this.Hide();
 
Share this answer
 
Comments
siasalar 27-Nov-12 6:05am    
great, tnx

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