C # code implementation on the welcome page of the form,
Call
WYL. orderWater. serverSide. splashScreen. splasher. show (typeof (WYL. orderWater. serverSide. splashScreen. frmSplash); System. threading. thread. sleep (1, 800); System. threading. thread. sleep (800 );//....... load the time-consuming code Splasher here. status = "Initialization is complete! "; System. Threading. Thread. Sleep (800); Splasher. Close ();
1.
Splasher. cs
using System;using System.Windows.Forms;using System.Threading;using System.Reflection;namespace WYL.OrderWater.ServerSide.SplashScreen{ public class Splasher { private static Form m_SplashForm = null; private static ISplashForm m_SplashInterface = null; private static Thread m_SplashThread = null; private static string m_TempStatus = string.Empty; /// /// Show the SplashForm /// public static void Show(Type splashFormType) { if (m_SplashThread != null) return; if (splashFormType == null) { throw (new Exception("splashFormType is null")); } m_SplashThread = new Thread(new ThreadStart(delegate() { CreateInstance(splashFormType); Application.Run(m_SplashForm); })); m_SplashThread.IsBackground = true; m_SplashThread.SetApartmentState(ApartmentState.STA); m_SplashThread.Start(); } /// /// set the loading Status /// public static string Status { set { if (m_SplashInterface == null || m_SplashForm == null) { m_TempStatus = value; return; } m_SplashForm.Invoke( new SplashStatusChangedHandle(delegate(string str) { m_SplashInterface.SetStatusInfo(str); }), new object[] { value } ); } } /// /// Colse the SplashForm /// public static void Close() { if (m_SplashThread == null || m_SplashForm == null) return; try { m_SplashForm.Invoke(new MethodInvoker(m_SplashForm.Close)); } catch (Exception) { } m_SplashThread = null; m_SplashForm = null; } private static void CreateInstance(Type FormType) { object obj = FormType.InvokeMember(null, BindingFlags.DeclaredOnly | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.CreateInstance, null, null, null); m_SplashForm = obj as Form; m_SplashInterface = obj as ISplashForm; if (m_SplashForm == null) { throw (new Exception("Splash Screen must inherit from System.Windows.Forms.Form")); } if (m_SplashInterface == null) { throw (new Exception("must implement interface ISplashForm")); } if (!string.IsNullOrEmpty(m_TempStatus)) m_SplashInterface.SetStatusInfo(m_TempStatus); } private delegate void SplashStatusChangedHandle(string NewStatusInfo); }}
2. ISplashForm. cs
using System;using System.Collections.Generic;using System.Text;namespace WYL.OrderWater.ServerSide.SplashScreen{ /// /// interface for Splash Screen /// public interface ISplashForm { void SetStatusInfo(string NewStatusInfo); }}
3. Form code
FrmSplash. cs
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Text;using System.Windows.Forms;namespace WYL.OrderWater.ServerSide.SplashScreen{ public partial class frmSplash : Form,ISplashForm { public frmSplash() { InitializeComponent(); } #region ISplashForm void ISplashForm.SetStatusInfo(string NewStatusInfo) { lbStatusInfo.Text = NewStatusInfo; } #endregion private void frmSplash_Load(object sender, EventArgs e) { } }}
FrmSplash. designer. cs
Namespace WYL. OrderWater. ServerSide. SplashScreen {partial class frmSplash {////// Required designer variables. ///Private System. ComponentModel. IContainer components = null ;////// Clear all resources in use. //////If the managed resources should be released, the value is true; otherwise, the value is false. Protected override void Dispose (bool disposing) {if (disposing & (components! = Null) {components. Dispose ();} base. Dispose (disposing);} # code generated by region Windows Form Designer ////// The designer supports the required methods-do not // use the code editor to modify the content of this method. ///Private void InitializeComponent () {this. lbStatusInfo = new System. windows. forms. label (); this. label1 = new System. windows. forms. label (); this. label2 = new System. windows. forms. label (); this. suspendLayout (); // lbStatusInfo // this. lbStatusInfo. autoSize = true; this. lbStatusInfo. backColor = System. drawing. color. transparent; this. lbStatusInfo. font = new System. drawing. font ("", 9F, System. drawi Ng. fontStyle. bold, System. drawing. graphicsUnit. point, (byte) (134); this. lbStatusInfo. foreColor = System. drawing. color. white; this. lbStatusInfo. location = new System. drawing. points (148,395); this. lbStatusInfo. name = "lbStatusInfo"; this. lbStatusInfo. size = new System. drawing. size (164, 12); this. lbStatusInfo. tabIndex = 0; this. lbStatusInfo. text = "initializing the application ...... "; // label1 // this. label1.Aut OSize = true; this. label1.Font = new System. drawing. font ("", 26.25F, System. drawing. fontStyle. bold, System. drawing. graphicsUnit. point, (byte) (134); this. label1.ForeColor = System. drawing. systemColors. highlightText; this. label1.Location = new System. drawing. point (144, 18); this. label1.Name = "label1"; this. label1.Size = new System. drawing. size (159, 35); this. label1.TabIndex = 1; this. label1.Te Xt = "Yinlong software"; // label2 // this. label2.AutoSize = true; this. label2.Font = new System. drawing. font ("", 10.5F, System. drawing. fontStyle. regular, System. drawing. graphicsUnit. point, (byte) (134); this. label2.ForeColor = System. drawing. systemColors. scrollBar; this. label2.Location = new System. drawing. points (50,536); this. label2.Name = "label2"; this. label2.Size = new System. drawing. size (161, 28); This. label2.TabIndex = 2; this. label2.Text = "(C) 2017 YinLongSoft. \ R \ n reserves all rights reserved. "; // FrmSplash // this. autoScaleDimensions = new System. drawing. sizeF (6F, 12F); this. autoScaleMode = System. windows. forms. autoScaleMode. font; this. backColor = System. drawing. systemColors. activeCaptionText; this. clientSize = new System. drawing. size (450,600); this. controls. add (this. label2); this. controls. add (this. label1); this. controls. add (this. lbStatusInfo); this. formBorderStyle = System. windows. forms. formBorderStyle. none; this. name = "frmSplash"; this. showInTaskbar = false; this. startPosition = System. windows. forms. formStartPosition. centerScreen; this. text = "frmSplash"; this. topMost = true; this. load + = new System. eventHandler (this. frmSplash_Load); this. resumeLayout (false); this. extends mlayout () ;}# endregion private System. windows. forms. label lbStatusInfo; private System. windows. forms. label label1; private System. windows. forms. label label2 ;}}
FrmSplash. resx