With the help of this link i made a splash screen. It works but the form which starts after the spash screen doesn't get the focus anymore. I need to activate it with a mouse click
Program.cs
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//show splash
Thread splashThread = new Thread(new ThreadStart(
delegate
{
splashForm = new FormSplashScreen();
Application.Run(splashForm);
}
));
splashThread.SetApartmentState(ApartmentState.STA);
splashThread.Start();
//run form - time taking operation
FormQueryBoxMain mainForm = new FormQueryBoxMain();
mainForm.Load += new EventHandler(mainForm_Load);
Application.Run(mainForm);
// Application.Run(new FormQueryBoxMain());
}
static void mainForm_Load(object sender, EventArgs e)
{
//close splash
if (splashForm == null)
{
return;
}
splashForm.Invoke(new Action(splashForm.Close));
splashForm.Dispose();
splashForm = null;
}
Main Form
private void FormMain_Load(object sender, EventArgs e)
{
Logging.StartLogging(); //this just starts the logging
}
private void FormMain_VisibleChanged(object sender, EventArgs e)
{
if (CheckLicense())
{
LoadTreeViewQueries();
//Inlog
FormGebruikerInlog ApplicatieLogIn = new FormGebruikerInlog(this, "Inlog Gebruiker");
ApplicatieLogIn.ShowDialog(this); --> This lost the focus.
}
else
{
LoadLicenseForm(); //Inlog voor licentie direct starten
}
}
ApplicatieLogIn.ShowDialog(this);
the form doesn't have the focus anymore.
First i had the code from FormMain_VisibleChanged
in the FormMain_Load
standing and then ApplicatieLogIn
opened on top and had focus
But that is not possible any more now i add the spashscreen.
How can i give ApplicatieLogIn
the focus back?
this.focus();
or this.actitive()
in the load of the ApplicatieLogIn doesn't the trick.