Tavousi
Tavousi

Reputation: 15446

close form1 & open form2

I used two forms in my windows application that they aren't my main form. Now I want to close form1 and open form2. How to I do this. Thanx.

Upvotes: 0

Views: 2822

Answers (2)

franklins
franklins

Reputation: 3738

I did this once for my project, to close one application and open another application.

    System.Threading.Thread newThread;
    Form1 frmNewForm = new Form1;

   newThread = new System.Threading.Thread(new System.Threading.ThreadStart(frmNewFormThread));
this.Close();
        newThread.SetApartmentState(System.Threading.ApartmentState.STA);
        newThread.Start();

And add the following Method. Your newThread.Start will call this method.

    public void frmNewFormThread)()
    {

        Application.Run(frmNewForm);

    }

Upvotes: 1

SwDevMan81
SwDevMan81

Reputation: 49978

Take a look at Hiding and Showing Forms for a good example of various techniques.

Major points include:

  • Creating a C# Application Containing Multiple Forms
  • Understanding Modal and Non-modal Forms
  • Writing C# Code to Display a Non-Modal Form
  • Writing C# Code to Display a Modal Form
  • Hiding Forms in C#
  • Closing Forms in C#

Upvotes: 4

Related Questions