views:

417

answers:

1

Normally I would do Application.Run(myMainForm).

But I want to do something like this:

MyForm1 f = new MyForm1();
f.Close+=OnOpenOverviewWin();
Application.Run(f);

void OnOpenOverviewWin()
{
MyOverViewForm f = new MyOverViewForm ();
Application.Run(f); // i want to do this
Application.NewMainWindow = f; // or something like that
}
+2  A: 

Set the Application.ShutdownMode property to ShutdownMode.OnLastWindowClose

MyForm1 f = new MyForm1();
f.Close += OnOpenOverviewWin();
Application.ShutdownMode = ShutdownMode.OnLastWindowClose;
Application.Run(f);

void OnOpenOverviewWin()
{
  MyOverViewForm f = new MyOverViewForm ();
  f.Show();
}
heavyd
has the mainwindow no other implications than that the app is closed?
codymanix
The MainWindow property will get changed if you close the first window opened. You can also set the MainWindow to your new window in your close handler rather than changing the ShutdownMode.
heavyd
Which MainWindow property? The Application class doesn't have such a thing.
codymanix
Sorry, I was looking at the wrong Application class. You're right, there is no MainWindow property. That property was added in the WPF version of the Application class, so you'll have to change the ShutdownMode.
heavyd
The ShutdownMode property also is defined on the WPF-Application class only.
codymanix