Windows Develop Bookmark and Share   
 index > Windows Forms General > Splash screen thread causing lost focus on main application form
 

Splash screen thread causing lost focus on main application form

I'm working on a splash screen for our windows application and I've got it just about nailed down but I have 1 small problem that I can't seem to get around.


Here's some background:
The exe fires up and a splash screen is displayed in a seperate thread while all of the application load logic takes place, BEFORE the main application form is displayed and the windows message pump is started. My problem is that the main form does not have focus and lies in the background of whatever window I have open (window explorer, visual studio, etc...) when it loads. I can click on the taskbar to bring it up, but it should be the primary focus after the splash screen loads and goes away.

Setting my MainForm to be TopMost before I call Application.Run solves it, but I don't want my form to be TopMost... just displayed as the active window when the splash screen thread dies, but I can't seem to make it happen. You can ignore the fact that the splash screen shows up and goes away immediately in my example, I have a more detailed splash screen in place with delegates for closing it, but this causes the same effect.

Here's the code:

Code Snippet
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();

// Display Splash Screen
Thread newThread = new Thread(new ThreadStart(StartSplashScreen));
newThread.IsBackground = true;
newThread.Name = "Splash Screen Thread";
newThread.Start();

// TODO: Application Load Logic

// Kill the Splash Screen Thread
newThread.Join();

// Main Application Form
MainForm mainForm = new MainForm();
Application.Run(mainForm);
}

// Entry Method for Splash Screen GUI Thread
public static void StartSplashScreen()
{
SplashForm form = new SplashForm();
form.Name = "Splash Screen";
form.Show();
}


Any suggestions?

Thanks in advance.
Josh
Josh Starner  Monday, November 03, 2008 2:42 PM
Getting a splash screen right can be tricky. It is best to use the support for it that's built-in to the .NET framework.
nobugz  Monday, November 03, 2008 4:02 PM
Getting a splash screen right can be tricky. It is best to use the support for it that's built-in to the .NET framework.
nobugz  Monday, November 03, 2008 4:02 PM

You can use google to search for other answers

Custom Search

More Threads

• Windows Forms designer moves my controls on build
• Drawing a blurred shadow
• Zoom event for picturebox
• My Wish List...
• Insert Data from excel to SQL server
• Weird about box problem
• dynamically change height of datagridview after adding rows programmatically.
• locking of combo box
• Why the WebBrowser vertical scrollbar is always shown?
• Scroll on mousescroll