c# winform 欢迎界面时加载数据
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace WindowsFormsApplication1 { public partial class WelcomeForm : Form { public WelcomeForm() { InitializeComponent(); } private void WelcomeForm_Load(object sender, EventArgs e) { //Thread.Sleep(2000); //this.Close(); //this.Dispose(); } public void KillMe(object o, EventArgs e) { this.Close(); } /// <summary> /// 加载并显示主窗体 /// </summary> /// <param name="form">主窗体</param> public static void LoadAndRun(Form form) { //订阅主窗体的句柄创建事件 form.HandleCreated += delegate { //启动新线程来显示Splash窗体 new Thread(new ThreadStart(delegate { WelcomeForm splash = new WelcomeForm(); //订阅主窗体的Shown事件 form.Shown += delegate { //通知Splash窗体关闭自身 splash.Invoke(new EventHandler(splash.KillMe)); splash.Dispose(); }; // Thread.Sleep(2000); //显示Splash窗体 Application.Run(splash); })).Start(); }; //显示主窗体 Application.Run(form); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Threading; namespace WindowsFormsApplication1 { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { //Thread.Sleep(2000); for (int i = 0; i < 100; i++) { Thread.Sleep(100); } //this.Focus(); MessageBox.Show("加载完毕!"); } } }
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; using System.Threading; namespace WindowsFormsApplication1 { static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); WelcomeForm.LoadAndRun(new Form1()); } } }