Form_Welcome.cs 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading;
  9. using System.Windows.Forms;
  10. namespace WelcomeForm
  11. {
  12. public partial class Form_Welcome : Form
  13. {
  14. public Form_Welcome()
  15. {
  16. InitializeComponent();
  17. }
  18. /// <summary>
  19. /// 关闭自身
  20. /// </summary>
  21. /// <param name="o"></param>
  22. /// <param name="e"></param>
  23. public void KillMe(object o, EventArgs e)
  24. {
  25. this.Close();
  26. }
  27. /// <summary>
  28. /// 加载并显示主窗体
  29. /// </summary>
  30. /// <param name="form">主窗体</param>
  31. public static void LoadAndRun(Form form)
  32. {
  33. //订阅主窗体的句柄创建事件
  34. form.HandleCreated += delegate
  35. {
  36. //启动新线程来显示welcome窗体
  37. new Thread(new ThreadStart(delegate
  38. {
  39. Form_Welcome welcome = new Form_Welcome();
  40. //订阅主窗体的Shown事件
  41. form.Shown += delegate
  42. {
  43. //通知welcome窗体关闭自身
  44. welcome.DialogResult = DialogResult.Abort;
  45. //welcome.Invoke(new EventHandler(welcome.KillMe));
  46. //welcome.Dispose();
  47. };
  48. //显示welcome窗体
  49. //Application.Run(welcome);
  50. welcome.ShowDialog();
  51. })).Start();
  52. };
  53. //显示主窗体
  54. Application.Run(form);
  55. }
  56. }
  57. }