AngryOwl
AngryOwl

Reputation: 45

Close button c# windows forms

I am trying to close the app by clicking one button but it's not working.

this is my code.

 private void buttonclose_Click(object sender, EventArgs e)
    {
        Application.Exit();
    }

Upvotes: 0

Views: 2976

Answers (2)

SAM
SAM

Reputation: 99

Use this Code, it will diffidently work

private void btnExit_Click(object sender, EventArgs e)  
{
  this.Close();
}

Upvotes: 1

Frosch
Frosch

Reputation: 411

Like @Dialecticus said, it could be that you never registered the event handler. In your form designer, when you double click the button it will register the click event for you automatically. If you didn't do that and your code was just copy/pasted you would have to go into the events to "wire" them yourself.

If that's not your issue, you could try using Environment.Exit() or this.Close() instead.

Upvotes: 2

Related Questions