有没有在form中程序退出时执行的事件

elixir2002 2005-02-28 06:09:42
我在form中用Application.exit()退出程序,好象无法启动
Form_Closing和Form_Closed两个事件,
请问有没有用Application.exit()退出程序时执行的事件;
谢谢各位
...全文
195 18 打赏 收藏 转发到动态 举报
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
曲滨_銘龘鶽 2005-03-01
  • 打赏
  • 举报
回复
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
//在 Application.Run 映射事件
Application.ApplicationExit+=new EventHandler(Application_ApplicationExit);

Application.Run(new Form1());

}
private static void Application_ApplicationExit(object sender, EventArgs e)
{
//Application.Exit(); 后就走这里了。
System.Diagnostics.Debug .WriteLine("Application_ApplicationExit");
}
yufenfeila 2005-03-01
  • 打赏
  • 举报
回复
[STAThread]
static void Main()
{
Application.Run(new Form1());

//在这里写代码就可以了

}
yufenfeila 2005-03-01
  • 打赏
  • 举报
回复
用Application.Exit()退出的程序并不会调用protected override void OnClosing(CannelEventArgs e)
elixir2002 2005-03-01
  • 打赏
  • 举报
回复
谢谢大家!!给分
洪十二 2005-03-01
  • 打赏
  • 举报
回复
若webform的關閉事件也是這樣寫法嗎?
yizhixiaozhu 2005-02-28
  • 打赏
  • 举报
回复
dd
xiaobaolove 2005-02-28
  • 打赏
  • 举报
回复
up,学习
cdo 2005-02-28
  • 打赏
  • 举报
回复
ptotected override void OnClosing(CannelEventArgs e)
{
//处理代码
}

这样应该可行。
qltouming 2005-02-28
  • 打赏
  • 举报
回复
查看动态帮助得:
当调用 Application.Exit 方法以退出应用程序时,不引发 Form.Closed 和 Form.Closing 事件。如果在必须执行的其中一个事件中有验证代码,则在调用 Exit 方法之前,应分别为每个打开的窗体调用 Form.Close 方法。

所以如果要在退出时执行时什么代码,写在Form.Close 中,先执行,再exit。
xiongchen 2005-02-28
  • 打赏
  • 举报
回复
我用的方法是重载closing方法哦!
web_gus 2005-02-28
  • 打赏
  • 举报
回复
up
pyuan 2005-02-28
  • 打赏
  • 举报
回复
写在main主函数里面吧,一般都是用Application.run(new form1);开始一个窗口,你直接在后面写你要执行的代码,不正好是程序退出前执行的代码吗?
jimh 2005-02-28
  • 打赏
  • 举报
回复
Form_Closing和Form_Closed两个事件好像经常有问题,不能执行。
使用重写的方式就有没问题了,
ptotected override void OnClosing(CannelEventArgs e)
{
//处理代码
}
Night_Elf 2005-02-28
  • 打赏
  • 举报
回复
添加委托:
AddHandler Application.ThreadExit, AddressOf MytheadExitEvent

Sub MytheadExitEvent(ByVal sender As Object, ByVal e As System.EventArgs)
MessageBox.Show("关闭")
End Sub

在Application.exit中不知可不可以
aijing 2005-02-28
  • 打赏
  • 举报
回复
up
DeltaCat 2005-02-28
  • 打赏
  • 举报
回复
在 closing 里
-------------
e.Cancel = true;
// do something
e.Cancel = false;
elixir2002 2005-02-28
  • 打赏
  • 举报
回复
我知道
closing正在关闭
closed已经关闭
jialiang 2005-02-28
  • 打赏
  • 举报
回复
closing正在关闭
closed已经关闭

110,539

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧