C# Windows Form: On Close Do [Process]

前端 未结 6 2017
我在风中等你
我在风中等你 2021-01-03 20:19

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

6条回答
  •  Happy的楠姐
    2021-01-03 20:46

    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
       } 
    }
    

提交回复
热议问题