C# .NET - How To Close one Form and open other in windows application?

Asked By CSharp DotNet on 17-Aug-10 04:54 AM
HIii

i have a windows application. in which i want to navigate from one form to other on button click..

so i want to know that How To Close one Form and open other in windows application?
like it can be done in web application by Response.Redirect("url");
I want to know how it can be done in windows application.

I have used form's close and open peoperty. but it is not working properly.

SO Please explain me with example

Thanks in advance
samjayander thiagarajan replied to CSharp DotNet on 17-Aug-10 05:02 AM
Hi,

assume you are in form1 and if you want to navigate to form2, 

do like this:

Form2 frm2 = new Form2();
frm2.Show();
this.close();


Regards,
Sam.
Anand Malli replied to CSharp DotNet on 17-Aug-10 05:15 AM
Hi

It can not be done directly like simple calling the Close method,if your parent form is start up form of your application then closing that will close all the forms of the application,this is the basic fundamental behind winforms,go through below link which talks about that only

http://www.eggheadcafe.com/software/aspnet/28431521/how-close-down-parent-form-after-creating-new-form.aspx

let me know
thxs
Anoop S replied to CSharp DotNet on 17-Aug-10 06:42 AM
use hide method for main form like
Form2 frm2 = new Form2();
frm2.Show();
this.hide()
other wise your application will be close as Anand Malli explained in the above post, if its not main for then use  method given by samjayander thiagarajan
 
Goniey N replied to CSharp DotNet on 17-Aug-10 10:00 AM
//Use Below Code...
private void btnNext_Click(object sender, System.EventArgs e)
{
  Form2 Newfrm2 = new Form2();
  this.Enabled = false;
  this.SendToBack();
  Newfrm2.Show();
  this.Close();
}

Hope This Helps You...
harsh shah replied to CSharp DotNet on 18-Aug-10 06:52 AM
Hi,
on click  write below code

this.close() -- use for close a current form

form2  objform=new form2() -- create a object of a form. form2 it's a form name.

objform.show() -- use for open and show a form


Regards,

Harsh Shah
dhaval replied to samjayander thiagarajan on 16-Sep-10 03:58 AM
Thank u very much ... my problem is solved