Igor Marvinsky
Igor Marvinsky

Reputation: 387

Changing action on clicking the close window button

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

Answers (2)

Waqas Raja
Waqas Raja

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

rsbarro
rsbarro

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

Related Questions