I’m building an app in C# using VS 2008 – I’ve added a method of checking if a file has changed when it is closed, but this only works for the File>close menu. Is there any way to get the red X in the top right to actually do anything before shutting everything? If so, how? I’ve only been doing C# for a few days, and this is incredibly confusing – there are no methods for the overall interface window anywhere. Help is much appreciated. Thanks.
Share
Use the Form.FormClosing event. Or the FormClosed event, that comes later and cannot cancel the closng.
And from the File|Close menuItem, just Close() the Form.
If you do that, you have 1 spot (FormClosing) where all the possible ways of closing a Form (including ALT+F4 and TaskManager) converge.
Do take a look at e.CloseReason, you don’t want to be in the way when it is for example
WindowsShutDown