且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何关闭Form1并打开窗体2

更新时间:2023-12-06 15:57:40

您有一些所谓的 的ApplicationContext

You have something called the ApplicationContext for that.

使用这样的:

ApplicationContext applicationContext = new ApplicationContext();

FormX formX = new FormX(applicationContext);
applicationContext.MainForm = formX;

Application.Run(applicationContext);

在结束 Form1中,拱手的MainForm

FormY formY = new FormY(applicationContext);
applicationContext.MainForm = formY;



另一种方法是使静态的ApplicationContext 。这不会要求各地传递给它。

Another option is to make a static ApplicationContext. That wouldn't require passing it around.