Open Form2 from Form1, close Form1 from Form2

后端 未结 8 684
陌清茗
陌清茗 2020-12-03 13:06

Now, I have two forms, called form1 and form2, in the form1 there\'s a button, when I click it, then open the form2

Question: in the form2, I want to create a button

8条回答
  •  [愿得一人]
    2020-12-03 13:45

    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);
    
        }
    

提交回复
热议问题