In my application, the user is first presented with the log in screen, and the form that shows up after you log in has a menu bar.
On that menu bar are two items: "log out" and "exit". If the user selects the log out option, I want it to return to the aforementioned log in screen. If the user instead decided to click "exit", I prompt the user if they are sure they want to exit.
Unfortunately, when the user decides to close the program by clicking the "X" button on the window, it closes only the current form. My intention would be for it to close the entire application.
Basically, how can I exit the current application by intercepting the form closing event?
Under the Logout item, the strip code is:
private void logoutToolStripMenuItem_Click(object sender, EventArgs e)
{
Form_Login log = new Form_Login();
this.Close();
log.Show();
}
Under the Exit item, the strip code is:
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
if (MessageBox.Show("Are you sure to exit the programme ?","Exit",MessageBoxButtons.OKCancel)== DialogResult.OK)
{
Application.Exit();
}
}
And when I click the exit button, it closes the current form and I want to close the whole application.