【发布时间】:2013-09-11 16:54:35
【问题描述】:
如何在程序完全加载之前显示启动画面,然后自动关闭并显示主窗体!
【问题讨论】:
-
没有代码 sn-ps 演示特定编程问题的问题在这里被认为是题外话。
如何在程序完全加载之前显示启动画面,然后自动关闭并显示主窗体!
【问题讨论】:
您可以在第二个线程上创建启动画面,当您的应用程序启动时,您可以卸载您的第二个线程
public partial class SplashForm : Form
{
public SplashForm()
{
InitializeComponent();
}
//The type of form to be displayed as the splash screen.
private static SplashForm splashForm;
static public void Show(string txt)
{
// Make sure it is only launched once.
if (splashForm != null)
{
splashForm.BeginInvoke(new MethodInvoker(delegate { splashForm.label1.Text = txt; }));
return;
}
Thread thread = new Thread((ThreadStart)delegate { ShowForm(txt); });
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
static private void ShowForm(string txt)
{
splashForm = new SplashForm();
splashForm.label1.Text = txt;
Application.Run(splashForm);
}
//Delegate for cross thread call to close
private delegate void CloseDelegate();
static public void CloseForm()
{
splashForm.Invoke(new CloseDelegate(SplashForm.CloseFormInternal));
}
static private void CloseFormInternal()
{
splashForm.Close();
}
} 希望对你有帮助
【讨论】: