Right-click on the appropriate window and select "Properties". In the "Properties" section, click "Events." Double-click the FormClosing event.
The following code will be created in Windows Form Designer:
private void myWindow_FormClosing(object sender, FormClosingEventArgs e) { }
Just update the code to look like this (add e.Cancel = true; ):
private void myWindow_FormClosing(object sender, FormClosingEventArgs e) { e.Cancel = true; }
You are done!
Alternatively, if you want to disable the close, maximize and reduce buttons of the window:
You can right-click on the window in question and click on "Properties". In the Properties section, set the ControlBox property to false .
Derek w
source share