Sunday, June 26, 2011

Close one form from another

I wanted to open Form2 from Form1 and close Form1.I try this many times but it fails my code is this.

var F2=new Form2();
F2.show();
this.close();



I searched lot.but I could find any error of the code but Form1 doesn’t closed.Finally I found the answer.It’s my main program.

Application.Run(new Form1());

So I couldn’t close Form1.


But I found anther way to close previous one

 var f=new Form2();
 f.Show();
 this.Dispose(false);


It works for me.

No comments:

Post a Comment