关闭一个表单后重新启动应用程序 [英] Restarting app after one form closes

查看:72
本文介绍了关闭一个表单后重新启动应用程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




我有一个主表单和一个数据库选择表单。当有人选择选择数据库表单时,会打开一个新表单。


我希望能够看到该表单何时关闭,然后发送一个弹出文件说应用程序需要重新启动


我需要以下帮助

1.确定何时关闭

2.显示pop后,重启应用程序使用新设置


非常感谢任何帮助或相关教程

Hi

I got a main form and a database selection form. When someone selects the select database form, a new form opens up.

I want to be able to see when that for is closed and then send a popup saying the application needs to be restarted

I need help with the following
1. Determine when formed closed
2. After pop is displayed, restart the application with the new settings

Any help or relevant tutorials would be much appreciated

推荐答案

那么你可以在你的消息框中显示主窗体的Dispose方法。

然后你可以调用:

Well you could show your message box in the Dispose method of the main form.
You can then call:

展开 | 选择 | 换行 | 行号


感谢很棒的答案,但有没有办法告诉我的Form1何时关闭我的主程序应该重启还是我可以从任何形式重新启动整个应用程序?
Appreciate the awesome answer, but is there a way to tell when my Form1 is closed that my Main program should restart or can i restart the whole application from any form?


确定表单何时关闭应该很容易,研究代表和事件处理。您应该可以让您的子表单在关闭时向父表单发送消息。实际上,更简单的方法是将对主窗体的引用传递给子窗体,然后在子窗体的窗体关闭事件中,以您喜欢的任何方式通知父窗体。你在这里有相当多的选择:)


至于重启主应用程序,这有点不同。据我所知,一旦应用程序关闭它,它就失去了控制权。也就是说,如果你为你的应用程序设置一个控制循环(即你的主表单不是入口点),那么你可以重新启动它。我想你在Program.cs中技术上有这个......

Determining when the form is closed should be easy enough, look into delegates and event handling. You should be able to have your child form send a message to the parent form when it closes. An even easier way, actually, would be to pass a reference to the main form to your child form, then in the child form''s form closing event, notify the parent in whatever way you prefer. You''ve got a fair amount of options here :)

As for restarting the main application, that''s a little different. To my knowledge, once the application closes that''s it, you''ve lost control. That said, if you set up a controlling loop for your application (ie, your main form isn''t the entry point), then you can restart it. I suppose you technically have this in Program.cs...

展开 | 选择 | Wrap | 行号


这篇关于关闭一个表单后重新启动应用程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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