【问题标题】:How to show a Splash Screen until a program loads Completely in Winforms? [duplicate]如何在 Winforms 中完全加载程序之前显示启动画面? [复制]
【发布时间】:2013-09-11 16:54:35
【问题描述】:

如何在程序完全加载之前显示启动画面,然后自动关闭并显示主窗体!

【问题讨论】:

标签: c# winforms


【解决方案1】:

您可以在第二个线程上创建启动画面,当您的应用程序启动时,您可以卸载您的第二个线程

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();
   }

} 希望对你有帮助

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多