[英]restart Function in visual C#
I have a windows application I need to create a button that unload/close/restart the currunt form while its running and reload/reopen/restart the same form. 我有一个Windows应用程序,我需要创建一个按钮,以在运行时卸载/关闭/重新启动currunt表单,并重新加载/重新打开/重新启动同一表单。
How ?? 怎么样 ?? I tried the hide show thing but it keeps the old form running in the background
我尝试了隐藏秀的东西,但它使旧表格在后台运行
Application.Restart();
我找到了 ....
Application.Restart()
will restart your entire application. Application.Restart()
将重新启动整个应用程序。
Hide()
will only do what it says, hide the form. Hide()
只会执行它所说的,隐藏表单。 If you just want a fresh version of your form to reappear, you can just create a new one, Show()
it, and Close()
your current form. 如果只希望重新
Show()
表单的新版本,则可以创建一个新的表单,将其Show()
并Close()
当前的表单。
public void Restart()
{
var window = new MyForm();
window.Show();
this.Close();
}
You'll have 2 forms open for a very short time, so if you have any data connections that need to be closed, do so before reopening the form. 您将在很短的时间内打开2个表单,因此,如果您有任何需要关闭的数据连接,请在重新打开表单之前进行关闭。 To the end-user, it will happen so fast that they won't know 2 forms were open.
对于最终用户来说,它发生得如此之快,以至于他们不知道有2个表单是打开的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.