【问题标题】:Make sure c# winforms application calls specific function before terminating [duplicate]确保 c# winforms 应用程序在终止之前调用特定函数 [重复]
【发布时间】:2016-03-29 10:02:00
【问题描述】:

有没有办法在应用程序退出之前调用 C# Windows 窗体应用程序中的函数,独立于关闭应用程序的事件(即按“X”关闭、通过任务管理器终止等)

抱歉,我没有看到问题已经得到解答,但问题的表述并没有让我找到我要找的东西!

【问题讨论】:

    标签: c# .net windows winforms


    【解决方案1】:

    试试FormClosing事件:

    public Form1()
    {
        InitializeComponent();
        FormClosing += Form1_FormClosing;
    }
    
    void Form1_FormClosing(object sender, FormClosingEventArgs e)
    {
        //Do your stuff before form is closed
    }
    

    【讨论】:

    • OnFormClosing(FormClosingEventArgs e) 也可以吗?
    • @Steffen....OnFormClosing 引发FormClosing 事件。
    猜你喜欢
    • 2014-02-19
    • 2017-08-13
    • 2017-03-17
    • 2018-11-24
    • 2010-12-21
    • 2023-03-28
    • 2021-06-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多