Hidden form not closing

前端 未结 2 1455
一整个雨季
一整个雨季 2020-12-04 03:16

I have a C# Form, where you have Form1 shown at the start, and when you press Go you are taken to Form2. Form1

相关标签:
2条回答
  • 2020-12-04 03:44

    Try this:

    Hide();
    Form2 form2 = new Form2();
    form2.Closed += (s, args) => this.Close();
    form2.Show();
    

    This will close Form1 when you close Form2. If the user presses X or ALT+F4 or RightClick -> Close on Form2 The Form2 and the hidden Form1 will close.

    0 讨论(0)
  • 2020-12-04 03:59

    Use the FormClosed event on Form2 to exit the application.

    private void Form2_FormClosed(object sender, FormClosedEventArgs e)
    {
         Application.Exit();
    }
    
    0 讨论(0)
提交回复
热议问题