Windows窗体:在运行时更改应用程序主窗口

时间:2009-06-22 18:56:27

标签: c# .net winforms mainwindow

通常我会做Application.Run(myMainForm)。

但我想做这样的事情:

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
}

1 个答案:

答案 0 :(得分:2)

Application.ShutdownMode属性设置为ShutdownMode.OnLastWindowClose

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

void OnOpenOverviewWin()
{
  MyOverViewForm f = new MyOverViewForm ();
  f.Show();
}