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