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?
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.
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".
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.
this.Close();
Closes the form programmatically.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With