Open All Hours

Sometimes you want to ensure that the system will not automatically close down your application when it goes into the background. You can achieve this by handling the Closing event of your main form, the event arguments passed to your handler will allow you to Cancel the close. Therefore you can set a boolean member to ensure that the operation only succeeds once you decide it’s okay to close:-

bool keepopen = true;

private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e)




      e.Cancel = true;




Then based on some pre-determined action in your program you can set keepopen to false and the form will close down.

By Peter Foot

Microsoft Windows Development MVP