Click here to Skip to main content
15,914,452 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
ok im a newbie to windows form application, ive created a form which takes in values and submits it into a db but on button click i need to close the current form an redirect to another form, how can this be done. Thanks for ur help. Have a good day cheers
Posted
Comments
[no name] 24-Nov-11 5:43am    
Is your first form modal?

Use this code.

C#
Form2 f = new Form2();
this.Hide();
f.Show();
 
Share this answer
 
You can use this code on your button click event.

C#
Form2 fm2 = new Form2();
fm2.ShowDialog();


this will open a Form2 as new window. but if u want to close current and to open a new one, then you have to use MDIParent and MDIChild combination

http://msdn.microsoft.com/en-us/library/7aw8zc76(v=vs.80).aspx[^]

use
C#
fm2.Show();


if form2 is MDIChild.

Hop this helps..
 
Share this answer
 
on button click add this
Form1 newForm=new Form1();// Form1 is name of your form that u want to open
newForm.show();
this.close();
 
Share this answer
 

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