当前位置:   article > 正文

splashform 显示 主窗体 正解

splash form not on screen
  1. 下面是部分代码:
  2. AppStart 类,包含Main方法
  3. public class AppStart
  4. {
  5. public AppStart()
  6. {
  7. }
  8. [STAThread]
  9. static void Main(string[] args)
  10. {
  11. // 显示Splash窗体
  12. Splash.Show();
  13. DoStartup(args);
  14. // 关闭Splash窗体
  15. Splash.Close();
  16. }
  17. static void DoStartup(string[] args)
  18. {
  19. // 做需要的事情
  20. frmMain f = new frmMain();
  21. Application.Run(f);
  22. }
  23. }
  24. Splash功能类:
  25. public class Splash
  26. {
  27. static frmSplash MySplashForm = null;
  28. static Thread MySplashThread = null;
  29. static void ShowThread()
  30. {
  31. MySplashForm = new frmSplash();
  32. Application.Run(MySplashForm);
  33. }
  34. static public void Show()
  35. {
  36. if (MySplashThread != null)
  37. return;
  38. MySplashThread = new Thread(new ThreadStart(Splash.ShowThread));
  39. MySplashThread.IsBackground = true;
  40. MySplashThread.ApartmentState = ApartmentState.STA;
  41. MySplashThread.Start();
  42. }
  43. static public void Close()
  44. {
  45. if (MySplashThread == null) return;
  46. if (MySplashForm == null) return;
  47. try
  48. {
  49. MySplashForm.Invoke(new MethodInvoker(MySplashForm.Close));
  50. }
  51. catch (Exception)
  52. {
  53. }
  54. MySplashThread = null;
  55. MySplashForm = null;
  56. }
  57. static public string Status
  58. {
  59. set
  60. {
  61. if (MySplashForm == null)
  62. {
  63. return;
  64. }
  65. MySplashForm.StatusInfo = value;
  66. }
  67. get
  68. {
  69. if (MySplashForm == null)
  70. {
  71. throw new InvalidOperationException("Splash Form not on screen");
  72. }
  73. return MySplashForm.StatusInfo;
  74. }
  75. }
  76. }
  77. Splash 界面类:
  78. public class frmSplash : System.Windows.Forms.Form
  79. {
  80. private string _StatusInfo = "";
  81. public frmSplash()
  82. {
  83. InitializeComponent();
  84. }
  85. private void InitializeComponent()
  86. {
  87. //
  88. this.pictureBox1.Image = ((System.Drawing.Image)(resources.GetObject("pictureBox1.Image")));
  89. //
  90. }
  91. public string StatusInfo
  92. {
  93. set
  94. {
  95. _StatusInfo = value;
  96. ChangeStatusText();
  97. }
  98. get
  99. {
  100. return _StatusInfo;
  101. }
  102. }
  103. public void ChangeStatusText()
  104. {
  105. try
  106. {
  107. if (this.InvokeRequired)
  108. {
  109. this.Invoke(new MethodInvoker(this.ChangeStatusText));
  110. return;
  111. }
  112. labStatus.Text = _StatusInfo;
  113. }
  114. catch (Exception e)
  115. {
  116. // 异常处理
  117. }
  118. }
  119. }
  120. 主界面类:
  121. public class frmMain : System.Windows.Forms.Form
  122. {
  123. public frmMain()
  124. {
  125. InitializeComponent();
  126. Splash.Status = "状态:载入初始化模块";
  127. System.Threading.Thread.Sleep(1000);
  128. Splash.Status = "状态:载入管理模块";
  129. System.Threading.Thread.Sleep(1000);
  130. Splash.Status = "状态:载入打印模块";
  131. System.Threading.Thread.Sleep(1000);
  132. Splash.Status = "状态:载入插件模块";
  133. System.Threading.Thread.Sleep(1000);
  134. Splash.Status = "状态:连接数据库";
  135. System.Threading.Thread.Sleep(1000);
  136. Splash.Close();
  137. }
  138. }

  

转载于:https://www.cnblogs.com/chinatrust/p/4489270.html

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/309505
推荐阅读
相关标签
  

闽ICP备14008679号