简体   繁体   中英

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.

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.

Hide() will only do what it says, hide the form. 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.

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. To the end-user, it will happen so fast that they won't know 2 forms were open.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM