I have two forms, the main and the second form. Since I want to easily move between them, while avoiding creating multiple instances of each of them, I used this in the main form :
Form2 secondForm = new Form2();
private void btnForm2_Click(object sender, EventArgs e)
{
secondForm.Show(this);
Hide();
}
and the code below in the second form :
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
e.cancel = true;
Owner.Show();
Hide();
}
Everything works just fine, except that I cannot close the application. When I move to the second form and return to the main one, the close button will not work.
How can I close the program while I am still using this code?
I also tried this code to see if the close button works:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
MessageBox.Show("Closing");
}
MessageBox was shown, but nothing happened after.