1

好的,form1 是我的“介绍”。我需要 form1 关闭和 form2...当它关闭时,整个应用程序关闭。我是新手,所以我不知道如何很好地解释我的问题...如果您有任何问题..请问... :)

4

3 回答 3

4

当我需要在显示主窗体之前有一个启动屏幕时,我使用的另一个解决方案是使用这个解决方案:

在你的 Program 类的 Main 函数中,你通常有这样的东西:

    [STAThread]
    static void Main(string[] ps)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());

    }

Application.Run 将应用程序绑定到表单,以便当表单关闭时,应用程序退出。如果您想在表格 1 之前显示表格 2,您可以这样做:

    [STAThread]
    static void Main(string[] ps)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Form1 splash = new Form1();
        splash.ShowDialog();
        Application.Run(new Form2());
    }

这个新代码将显示 form2。关闭form2后,它会显示form1。关闭 Form1 将退出应用程序。

通常 Splash 窗口是在另一个线程中创建的,让主线程加载它需要的数据。

于 2012-05-18T17:40:35.117 回答
1

您可以隐藏 From1,而不是关闭。

Form1.hide = true
于 2012-05-18T17:31:07.140 回答
0

您应该覆盖表单中的 OnClosing 方法...

protected override void OnClosing(CancelEventArgs e)
{
     e.Cancel = true;
     this.Hide();
}
于 2012-05-18T17:35:06.467 回答