static class Program
{
internal static ApplicationContext context = new ApplicationContext(new Form1());
///<summary>
/// 应用程序的主入口点。
///</summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
//Application.SetCompatibleTextRenderingDefault(false); 这句要注释掉,否则会出错
Application.Run(context);
}
}
然后这样显示窗体:
Form2 form = new Form2();
Program.context.MainForm = form;
form.Show();
this.Close();
就可以将上下文的主窗体设置为新的Form2了,然后关闭form1就不影响程序运行了