Alex Rivera | Logout

C# Windows Form: On Close Do [Process]

Asked 2010-05-25T15:11:30.910
27

How can I get my windows form to do something when it is closed.

Edit
Report

1 Answer

17

Or another alternative is to override the OnFormClosed() or OnFormClosing() methods from System.Windows.Forms.Form.

Whether you should use this method depends on the context of the problem, and is more usable when the form will be sub classed several times and they all need to perform the same code.

Events are more useful for one or two instances if you're doing the same thing.

public class FormClass : Form
{
   protected override void OnFormClosing(FormClosingEventArgs e)
   {
        base.OnFormClosing(e);
        // Code
   } 
}
answered 2010-05-25T15:22:20.913

Your Answer