views:

73

answers:

2

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

+3  A: 

Application.Restart();

I found it ....

nader
A: 

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.

Will Eddins