12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061 |
- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading;
- using System.Windows.Forms;
- namespace WelcomeForm
- {
- public partial class Form_Welcome : Form
- {
- public Form_Welcome()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 关闭自身
- /// </summary>
- /// <param name="o"></param>
- /// <param name="e"></param>
- public void KillMe(object o, EventArgs e)
- {
- this.Close();
- }
- /// <summary>
- /// 加载并显示主窗体
- /// </summary>
- /// <param name="form">主窗体</param>
- public static void LoadAndRun(Form form)
- {
- //订阅主窗体的句柄创建事件
- form.HandleCreated += delegate
- {
- //启动新线程来显示welcome窗体
- new Thread(new ThreadStart(delegate
- {
- Form_Welcome welcome = new Form_Welcome();
- //订阅主窗体的Shown事件
- form.Shown += delegate
- {
- //通知welcome窗体关闭自身
- welcome.DialogResult = DialogResult.Abort;
- //welcome.Invoke(new EventHandler(welcome.KillMe));
- //welcome.Dispose();
- };
- //显示welcome窗体
- //Application.Run(welcome);
- welcome.ShowDialog();
- })).Start();
- };
- //显示主窗体
- Application.Run(form);
- }
- }
- }
|