启动画面问题 – C# – VS2005

我有一个申请。

首先我显示一个启动画面,一个表单,这个启动会调用另一个表单。

问题:当显示启动窗体时,如果我然后在启动画面顶部打开另一个应用程序,然后最小化这个新打开的应用程序窗口,则启动画面变为白色。 我该如何避免这种情况? 我希望我的飞溅能够清晰显示,不受任何应用程序的影响。

您需要在不同的线程中显示启动画面 – 目前您的新表单加载代码正在阻止启动画面的UI线程。

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

重要的是要确保不要尝试从错误的线程修改UI控件 – 只使用创建控件的控件。

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

我有一个类似的问题,你可能想看看。 Stack Overflow的答案我完全适合我 – 你可能想看一看。