捕获应用程序退出事件 - 的WinForms [英] Capturing Application exit event - WinForms

查看:768
本文介绍了捕获应用程序退出事件 - 的WinForms的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是可能的应用程序停止点击时捕获Windows窗体关闭事件。
我知道,应用程序将停止工作,但没有任何可用的方法,谁在任何情况下火的时候,应用程序被关闭?
我发现从谷歌这些方法,但他们没有工作:

Is this possible to capture Windows form close event when clicked on application stop. I know application stop working but is there any method available who will fire in any case when application is closing? I found these methods from google but they are not working:

 AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);  

  Application.ApplicationExit += new EventHandler(this.OnApplicationExit); 

是否有可能去接近事件当点击应用程序停止按钮?

Is it possible to get close event when click on application stop button?

推荐答案

在Program.cs的文件,你必须有这些方法的之前 Application.Run:

In Program.cs file, you must have those methods before Application.Run :

    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.ApplicationExit += new EventHandler(Application_ApplicationExit);
        AppDomain.CurrentDomain.ProcessExit += new EventHandler(CurrentDomain_ProcessExit);
        Application.Run(new MainForm());
    }

您还可以使用处置事件在MainForm的(在申请使用的表格.RUN法)。

You can also use the Disposed event on the MainForm (the form used in Application.Run method).

这篇关于捕获应用程序退出事件 - 的WinForms的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆