I got two forms, main and second form. Since I want to navigate between them easily, while avoiding creating multiple instances of each, I used this at main form:
Form2 secondForm = new Form2();
private void btnForm2_Click(object sender, EventArgs e)
{
secondForm.Show(this);
Hide();
}
and the code below at second form:
private void Form2_FormClosing(object sender, FormClosingEventArgs e)
{
e.cancel = true;
Owner.Show();
Hide();
}
Everything works just perfect, except the fact that I can't close the application. When I go to second form and back to main, close button won't work anything at all.
How can I close the program while I still use this code?
I also tried this code to see if close button is working itself:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
MessageBox.Show("Closing");
}
MessageBox was shown, but nothing happened after.