在C#中处理Application.Exit(CancelEventArgs)

时间:2013-02-26 04:34:45

标签: c# event-handling

简单地说,我如何订阅和处理以下事件?

System.Windows.Forms.Application.Exit(new System.ComponentModel.CancelEventArgs(true));

因为显然这不会给我我的CancelEventArgs:

Application.ApplicationExit += new EventHandler(ApplicationExitHandler);
private void ApplicationExitHandler(Object sender, EventArgs e)
{
    ...
}

1 个答案:

答案 0 :(得分:1)

尝试将事件放在 Form1.Designer.cs

  private void InitializeComponent()
        {
          //.......... UI iniatilization

           System.Windows.Forms.Application.ApplicationExit +=new System.EventHandler(ApplicationExitHandler);

        }

Form1.cs

 private void ApplicationExitHandler(Object sender, EventArgs e)
        {
           //.............
        }