Goal:
Don't want the user to use the X mark (upper right of the program's screen) to exit the program.
Problem:
Don't know how to remove that icon that allows user to exit the program?
e. Cancel = true; This will prevent the window from closing. This has the same effect as hiding the close button.
The Close button is at the far right end of the title bar. It looks like a box with an X in it. You can click the Close button to close a window or exit an application.
You can set the ControlBox
property to false
if you don't want this to display. This will also remove the minimize and maximize buttons, mind you.
I would also ask you to consider why you want to remove this button. Sometimes it makes more sense to override the OnFormClosing
method and optionally set Cancel
to true
under certain conditions (e.g., e.CloseReason == CloseReason.UserClosing
).
myForm.ControlBox = false;
Apparently I have to have at least 30 characters in my post, so I will say that I am assuming WinForms since you do not specify yourself. Also note that setting this property to false will remove the minimize and maximize buttons as well.
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