Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using Exit button to close a winform program

Tags:

c#

winforms

I have an exit button on a winform that I want to use to close the program. I have added the button name to the FormClosed property found in the events section of the winforms properties. I thought that's all I had to do but when I click the button it does not close. I looked at the code and while a handler is created, there is no code inside of it. I don't know if that is correct or not. Here is the code that was created in the Form.cs file:

private void btnExitProgram_Click(object sender, EventArgs e)
    {

    }

What else do I have to do?

like image 695
Programming Newbie Avatar asked Mar 06 '12 15:03

Programming Newbie


People also ask

How do I close a winform button?

When we need to exit or close opened form then we should use "this. Close( )" method to close the form on some button click event. When we are running a winform application & need to exit or close SUB APPLICATION or CURRENT THREAD then we should use "System. Windows.

How do I stop a program in C#?

Exit() will end the process with the exit code you specify. Combine one of the tests above with Environment. Exit() (and probably an if ) and you can stop the process when there's no "value or data".

Which of the following method is used to close the windows form application?

Exit method is called to exit your application. If you have validation code in either of these events that must be executed, you should call the Form.


1 Answers

this.Close();

Closes the form programmatically.

like image 120
bschultz Avatar answered Sep 17 '22 04:09

bschultz