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 ke开发者_运维技巧eps the old form running in the background
Application.Restart();
I found it ....
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.
精彩评论