WinForm 程序启动时不显示主窗体
WinForm程序启动时不显示主窗体的实现方法,试来试去还是这个方法比较好:
1 using System;
2 using System.Collections.Generic;
3 using System.Windows.Forms;
4
5 namespace winAppTest1
6 {
7 static class Program
8 {
9 /// <summary>
10 /// The main entry point for the application.
11 /// </summary>
12 [STAThread]
13 static void Main()
14 {
15 Application.EnableVisualStyles();
16 Application.SetCompatibleTextRenderingDefault(false);
17 //Application.Run(new Form1());
18
19 Application.Run(new AppContext(new Form1()));
20 }
21 }
22
23
24 internal class AppContext : ApplicationContext
25 {
26 private Form mainForm;
27
28 public AppContext(Form mainForm)
29 {
30 this.mainForm = mainForm;
31 this.mainForm.Closed += new EventHandler(mainForm_Closed);
32 }
33
34 // 主窗体被关闭时,退出应用程序
35 void mainForm_Closed(object sender, EventArgs e)
36 {
37 Application.Exit();
38 }
39 }
40 }
2 using System.Collections.Generic;
3 using System.Windows.Forms;
4
5 namespace winAppTest1
6 {
7 static class Program
8 {
9 /// <summary>
10 /// The main entry point for the application.
11 /// </summary>
12 [STAThread]
13 static void Main()
14 {
15 Application.EnableVisualStyles();
16 Application.SetCompatibleTextRenderingDefault(false);
17 //Application.Run(new Form1());
18
19 Application.Run(new AppContext(new Form1()));
20 }
21 }
22
23
24 internal class AppContext : ApplicationContext
25 {
26 private Form mainForm;
27
28 public AppContext(Form mainForm)
29 {
30 this.mainForm = mainForm;
31 this.mainForm.Closed += new EventHandler(mainForm_Closed);
32 }
33
34 // 主窗体被关闭时,退出应用程序
35 void mainForm_Closed(object sender, EventArgs e)
36 {
37 Application.Exit();
38 }
39 }
40 }
本文地址:http://www.cnblogs.com/anjou/archive/2006/04/18/378022.html
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】凌霞软件回馈社区,博客园 & 1Panel & Halo 联合会员上线
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步