2

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
}
codymanix
  • 28,510
  • 21
  • 92
  • 151

1 Answers1

2

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
  • 17,303
  • 5
  • 56
  • 74
  • has the mainwindow no other implications than that the app is closed? – codymanix Jun 22 '09 at 21:10
  • 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 Jun 22 '09 at 21:22
  • Which MainWindow property? The Application class doesn't have such a thing. – codymanix Jun 23 '09 at 18:52
  • 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 Jun 23 '09 at 19:35
  • 2
    The ShutdownMode property also is defined on the WPF-Application class only. – codymanix Jul 04 '09 at 12:07