Click here to Skip to main content
15,881,092 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi I am a newbie in .Net so i am facing so much trouble some time here is one ,I have 2 form(Form1 & form2) and the form1 contain a button on it when i will click on the button the second form should be open and the form1 need to be closed .plea help me....
Posted

You can just hide Form1 where as you cannot close it because Form1 is parent form and it cannot be closed unless child form is closed
 
Share this answer
 
Hi
In the Click event of the button use this code

C#
Form2 test = new Form2();
test.Show();
this.Hide();


Using this you can show form2 and the form1 will disappear.
 
Share this answer
 
//creating the child form in Parent Form
Form2 f=new Form2();
f.show(this);
this.Hide(); //hiding the parent form


///closing Event in child form
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
this.Owner.Dispose(); //closing parent form
}
 
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