启动画面的问题 - C# - VS2005

问题描述:

我有一个应用程序。启动画面的问题 - C# - VS2005

首先我显示启动画面,一种形式,这飞溅称之为另一种形式。

问题:当显示飞溅形式,如果我再打开就扑通顶部其他应用程序,然后最小化这个新打开的应用程序窗口,启动画面变成白色。我如何避免这种情况?我希望我的飞溅清晰显示,不受任何应用程序的影响。

你需要在不同的线程来显示启动画面 - 目前新的形式加载代码挡住了闪屏的UI线程。

启动一个新的线程,该线程创建闪屏和呼叫Application.Run(splash)。这将在该线程上启动一个新的消息泵。然后,您需要在启动屏幕的UI线程(例如,使用Control.Invoke/BeginInvoke)准备好后,将其主线程调用回线程,以便启动屏幕可以自行关闭。

重要的是要确保你不要试图修改从错误的线程UI控件 - 仅使用控制上创建的一个。

+1

不幸的是,这对初学者来说相当复杂。我确定有一些图书馆或者这样做了吗? – configurator 2008-12-25 13:49:33

+0

我不知道框架中的任何内容。可能会有第三方库让它更容易。 – 2008-12-25 18:53:58

我有一个类似的问题,你可能想看看。 Stack Overflow answer我得到了完美的工作 - 你可能想看看。

NET框架有闪屏优异的内置支持。启动一个新的WF项目,Project + Add Reference,选择Microsoft.VisualBasic。添加一个新表单,将其命名为frmSplash。打开Project.cs并使其看起来像这样:

using System; 
using System.Windows.Forms; 
using Microsoft.VisualBasic.ApplicationServices; 

namespace WindowsFormsApplication1 { 
    static class Program { 
    [STAThread] 
    static void Main(string[] args) { 
     Application.EnableVisualStyles(); 
     Application.SetCompatibleTextRenderingDefault(false); 
     new MyApp().Run(args); 
    } 
    } 
    class MyApp : WindowsFormsApplicationBase { 
    protected override void OnCreateSplashScreen() { 
     this.SplashScreen = new frmSplash(); 
    } 
    protected override void OnCreateMainForm() { 
     // Do your time consuming stuff here... 
     //... 
     System.Threading.Thread.Sleep(3000); 
     // Then create the main form, the splash screen will close automatically 
     this.MainForm = new Form1(); 
    } 
    } 
}