Reputation: 387
I'd like for the 'x' button on the title bar to close the whole application, not the current form. How do I do that?
Upvotes: 4
Views: 3249
Reputation: 10870
@rsbarro is right however I want to be more specific.
private void Form_FormClosed(object sender, FormClosingEventArgs e)
{
// if close button clicked, not the computer is being shutdown or anyother reason
if (e.CloseReason == CloseReason.UserClosing)
{
Application.Exit();
}
}
Upvotes: 2
Reputation: 27339
Wire up an event handler for the FormClosed
event on the form and call Application.Exit()
. For example:
private void Form2_FormClosed(object sender, FormClosedEventArgs e)
{
Application.Exit();
}
Upvotes: 4