Click here to Skip to main content
15,897,704 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have two forms form1 have one button when i click button its open form2 but i want to close form1 also. i am using following line of code, but its not working. how to do it,please help
//buttom1 of form1
button1_click
{
form2 f2=new form2();
f2.show();
form1 f1=new form1();
f1.close();
}
Posted

Hi,
Use following code:
C#
Form2 frm = new Form2(this);
          frm.Show();
          this.Hide();
 
Share this answer
 
Comments
member60 6-Mar-13 6:53am    
my 5!
giri001 6-Mar-13 7:40am    
Thanks..:-)
Hi,
if your form 1 is the main form you cannot close the main form, instead you can hide them using the ".Hide()" call. This is because if you close your main form, you will lose some context of your application.

However, in your code
form2 f2=new form2();
f2.show();
form1 f1=new form1();
f1.close();

is pointless, you haven't showed your form 1 in the first place to close.


Regards
Jegan
 
Share this answer
 
Try this..

button1_click
{
Form1.visible="False";

Form2.Visible="true"
}
 
Share this answer
 
v2

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