How to show a splash screen until a program loads completely and then it Closes automatically and shows a main form !
Asked
Active
Viewed 3,606 times
-7
-
5Questions without code snippets demonstrating a particular programming problem are considered off-topic here. – BartoszKP Sep 07 '13 at 19:51
-
Check : http://stackoverflow.com/questions/1918158/how-do-i-show-a-loading-please-wait-message-in-winforms-for-a-long-loadi – Sep 07 '13 at 19:52
-
Also Check : http://stackoverflow.com/questions/5743458/show-a-splash-screen-at-once – Sep 07 '13 at 19:54
-
See Also : http://stackoverflow.com/questions/48916/multi-threaded-splash-screen-in-c?rq=1 – Sep 07 '13 at 19:54
1 Answers
1
you can create your splash on second thread and when your application has started you can unload your second thread
public partial class SplashForm : Form
{
public SplashForm()
{
InitializeComponent();
}
//The type of form to be displayed as the splash screen.
private static SplashForm splashForm;
static public void Show(string txt)
{
// Make sure it is only launched once.
if (splashForm != null)
{
splashForm.BeginInvoke(new MethodInvoker(delegate { splashForm.label1.Text = txt; }));
return;
}
Thread thread = new Thread((ThreadStart)delegate { ShowForm(txt); });
thread.IsBackground = true;
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
static private void ShowForm(string txt)
{
splashForm = new SplashForm();
splashForm.label1.Text = txt;
Application.Run(splashForm);
}
//Delegate for cross thread call to close
private delegate void CloseDelegate();
static public void CloseForm()
{
splashForm.Invoke(new CloseDelegate(SplashForm.CloseFormInternal));
}
static private void CloseFormInternal()
{
splashForm.Close();
}
} hope this help

BRAHIM Kamel
- 13,492
- 1
- 36
- 47