在Program类中
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就不会影响程序运行了

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-07-10
  • 2022-03-06
  • 2021-11-28
  • 2022-12-23
  • 2021-10-24
  • 2021-06-24
猜你喜欢
  • 2022-12-23
  • 2022-02-23
  • 2022-12-23
  • 2022-12-23
  • 2021-09-23
  • 2022-12-23
相关资源
相似解决方案