gpt4 book ai didi

c# - 允许 Form1 关闭而不关闭 C# 中的应用程序?

转载 作者:太空宇宙 更新时间:2023-11-03 20:25:55 25 4
gpt4 key购买 nike

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

最佳答案

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

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

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

}

Application.Run 将应用程序绑定(bind)到表单,以便在表单关闭时应用程序退出。如果你想在表格 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 窗口是在另一个线程中创建的,让主线程加载它需要的数据。

关于c# - 允许 Form1 关闭而不关闭 C# 中的应用程序?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10657152/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com