JSJ*_*JSJ 32
您需要创建一个表单作为启动画面,并在主开始显示登录页面之前显示它,并在加载登录页面后关闭此启动画面.
using System.Threading;
using System.Windows.Forms;
namespace MyTools
{
public class SplashForm : Form
{
//Delegate for cross thread call to close
private delegate void CloseDelegate();
//The type of form to be displayed as the splash screen.
private static SplashForm splashForm;
static public void ShowSplashScreen()
{
// Make sure it is only launched once.
if (splashForm != null)
return;
Thread thread = new Thread(new ThreadStart(SplashForm.ShowForm));
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
static private void ShowForm()
{
splashForm = new SplashForm();
Application.Run(splashForm);
}
static public void CloseForm()
{
splashForm.Invoke(new CloseDelegate(SplashForm.CloseFormInternal));
}
static private void CloseFormInternal()
{
splashForm.Close();
splashForm = null;
}
}
}
Run Code Online (Sandbox Code Playgroud)
并且主程序功能如下所示:
[STAThread]
static void Main(string[] args)
{
SplashForm.ShowSplashScreen();
MainForm mainForm = new MainForm(); //this takes ages
SplashForm.CloseForm();
Application.Run(mainForm);
}
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
41078 次 |
最近记录: |