views:

967

answers:

3

Dear all,

I have an application.

First I display a splash screen, a form, and this splash would call another form.

Problem: When the splash form is displayed, if I then open another application on the top of the splash, and then minimize this newly opened application window, the splash screen becomes white. How do I avoid this? I want my splash to be displayed clearly and not affected by any application.

+4  A: 

You need to display the splash screen in a different thread - currently your new form loading code is blocking the splash screen's UI thread.

Start a new thread, and on that thread create your splash screen and call Application.Run(splash). That will start a new message pump on that thread. You'll then need to make your main UI thread call back to the splash screen's UI thread (e.g. with Control.Invoke/BeginInvoke) when it's ready, so the splash screen can close itself.

The important thing is to make sure that you don't try to modify a UI control from the wrong thread - only use the one the control was created on.

Jon Skeet
Unfortunately, that's rather complicated for beginners. I was sure there was some library or something that did that?
configurator
I don't know of anything in the framework. There may be third party libraries to make it easier.
Jon Skeet
+1  A: 

I had a similar issue you might want to check out. The Stack Overflow answer I got worked perfectly for me - you may want to take a look.

John Virgolino
+3  A: 

The .NET framework has excellent built-in support for splash screens. Start a new WF project, Project + Add Reference, select Microsoft.VisualBasic. Add a new form, call it frmSplash. Open Project.cs and make it look like this:

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();
    }
  }
}
Hans Passant
Thanks for this - nice and simple
HigherAbstraction