473,398 Members | 2,812 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

winform startup/splash screen

Tom
Hi all

In winform application I am trying to start 2 forms I am trying to show the
2nd winform on a separate thread.
using
Thread mainapp = new Thread(new ThreadStart(loadmainscm));

mainapp.Start();

//where

private void loadmainscm() {

SCM.frmSplash frmsplash = new frmSplash();

frmsplash.Show();

Thread.Sleep(10000);

}
However the 2nd form will show but the graphics and controls are not
rendered when I use Thread.Sleep(10000); ... if I do not use
Thread.Sleep(10000); then the form will show and then quickly close itself,
I believe the thread will stop itself once the form has started.

what I am trying to achieve is a splash screen or a startup screen. does
anyone have any better idea ? or how I can achieve this ?

Thanks
Tom
Nov 17 '05 #1
2 20580
Hi Tom,
I would do something like the following:

1. Create a splash form (like you have), look at LaunchSplash and
CloseSplash. These two methods are static to easily help launch and close
the form:

//SplashScreen.cs

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;

namespace WindowsApplication4
{
public class SplashScreen : Form
{
private static Thread _splashLauncher;
private static SplashScreen _splashScreen;

private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "SplashScreen";
}
#endregion

private SplashScreen()
{
InitializeComponent();
}

public static void ShowSplash()
{
//Show the form in a new thread
_splashLauncher = new Thread(new ThreadStart(LaunchSplash));
_splashLauncher.IsBackground = true;
_splashLauncher.Start();

}

private static void LaunchSplash()
{
_splashScreen = new SplashScreen();

//Create new message pump
Application.Run(_splashScreen);
}

private static void CloseSplashDown()
{
Application.ExitThread();
}

public static void CloseSplash()
{
//Need to get the thread that launched the form, so
//we need to use invoke.
MethodInvoker mi = new MethodInvoker(CloseSplashDown);
_splashScreen.Invoke(mi);
}
}
}

2. Need to make a call to launch the splash screen, this can be done in your
main method:

[STAThread]
static void Main()
{
//Show the flash ASAP
SplashScreen.ShowSplash();

Application.Run(new Form1());
}
3. Finally in the constructor for your main form do all the loading work you
have to do (I put a thread.Sleep to simulate this) and then close the
SplashScreen last:

//Form1.cs

public Form1()
{
//Simulate some work
System.Threading.Thread.Sleep(5000);

InitializeComponent();

//Close the splash
SplashScreen.CloseSplash();
}
Hope that helps
Mark R Dawson
http://www.markdawson.org

"Tom" wrote:
Hi all

In winform application I am trying to start 2 forms I am trying to show the
2nd winform on a separate thread.
using
Thread mainapp = new Thread(new ThreadStart(loadmainscm));

mainapp.Start();

//where

private void loadmainscm() {

SCM.frmSplash frmsplash = new frmSplash();

frmsplash.Show();

Thread.Sleep(10000);

}
However the 2nd form will show but the graphics and controls are not
rendered when I use Thread.Sleep(10000); ... if I do not use
Thread.Sleep(10000); then the form will show and then quickly close itself,
I believe the thread will stop itself once the form has started.

what I am trying to achieve is a splash screen or a startup screen. does
anyone have any better idea ? or how I can achieve this ?

Thanks
Tom

Nov 17 '05 #2
Tom
Thanks Mark

I really liked your explaination. It worked and helped me alot !

Thankyou for taking the time to draw up the sample code it was very helpful

Tom

"Mark R. Dawson" <Ma*********@discussions.microsoft.com> wrote in message
news:81**********************************@microsof t.com...
Hi Tom,
I would do something like the following:

1. Create a splash form (like you have), look at LaunchSplash and
CloseSplash. These two methods are static to easily help launch and close
the form:

//SplashScreen.cs

using System;
using System.Drawing;
using System.Windows.Forms;
using System.Threading;

namespace WindowsApplication4
{
public class SplashScreen : Form
{
private static Thread _splashLauncher;
private static SplashScreen _splashScreen;

private System.ComponentModel.IContainer components = null;

/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be
disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}

#region Windows Form Designer generated code

/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.Text = "SplashScreen";
}
#endregion

private SplashScreen()
{
InitializeComponent();
}

public static void ShowSplash()
{
//Show the form in a new thread
_splashLauncher = new Thread(new ThreadStart(LaunchSplash));
_splashLauncher.IsBackground = true;
_splashLauncher.Start();

}

private static void LaunchSplash()
{
_splashScreen = new SplashScreen();

//Create new message pump
Application.Run(_splashScreen);
}

private static void CloseSplashDown()
{
Application.ExitThread();
}

public static void CloseSplash()
{
//Need to get the thread that launched the form, so
//we need to use invoke.
MethodInvoker mi = new MethodInvoker(CloseSplashDown);
_splashScreen.Invoke(mi);
}
}
}

2. Need to make a call to launch the splash screen, this can be done in
your
main method:

[STAThread]
static void Main()
{
//Show the flash ASAP
SplashScreen.ShowSplash();

Application.Run(new Form1());
}
3. Finally in the constructor for your main form do all the loading work
you
have to do (I put a thread.Sleep to simulate this) and then close the
SplashScreen last:

//Form1.cs

public Form1()
{
//Simulate some work
System.Threading.Thread.Sleep(5000);

InitializeComponent();

//Close the splash
SplashScreen.CloseSplash();
}
Hope that helps
Mark R Dawson
http://www.markdawson.org

"Tom" wrote:
Hi all

In winform application I am trying to start 2 forms I am trying to show
the
2nd winform on a separate thread.
using
Thread mainapp = new Thread(new ThreadStart(loadmainscm));

mainapp.Start();

//where

private void loadmainscm() {

SCM.frmSplash frmsplash = new frmSplash();

frmsplash.Show();

Thread.Sleep(10000);

}
However the 2nd form will show but the graphics and controls are not
rendered when I use Thread.Sleep(10000); ... if I do not use
Thread.Sleep(10000); then the form will show and then quickly close
itself,
I believe the thread will stop itself once the form has started.

what I am trying to achieve is a splash screen or a startup screen. does
anyone have any better idea ? or how I can achieve this ?

Thanks
Tom

Nov 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: John | last post by:
Can anybody tell me how I can make the splash screen stay up longer then the brief few micro seconds it does now. Any code required for this? Can I select the number of seconds for the screen to...
2
by: BuzzLight | last post by:
This is my problem :- - I have set a form frmSplash as the startup form instead of sub Main. - This means I dont create an instance of it myself at startup.. its automatically created. - I have...
2
by: Joe Cool | last post by:
Using VB in VS2005. 2005 has a new way to implment a spash screen that alleviates the need for hardly any code. But I have found that when a GUI that has a splash screen is run as a scheduled task,...
5
by: steve | last post by:
Hi All I have a form set as the splash screen in VB.net 2005 application properties How can I tell when it has or is closing, as I want to then run some licence checking code without the...
3
by: steve | last post by:
Hi All I have a VB.net 2005 App which has a form set as the Application splash screen in Project properties Another form is set as the startup form All works great until the splash screen...
2
by: Mika M | last post by:
Hi! My Windows Forms VB 2005 application has Splash Screen form specified in My Project/Application/Splash Screen. How can I close Splash Screen form programmatically when Startup form...
2
by: will_456 | last post by:
In vb2005 Express: In My Project Application Splash Screen I have selected my splash screen form. The form opens on project startup but closes immediately before anyone would have time to read...
1
by: BRAHM | last post by:
I am using this code to set up the splash screen startup time. Protected Overrides Function OnInitialize( _ ByVal commandLineArgs As _ System.Collections.ObjectModel.ReadOnlyCollection(Of...
1
by: BRAHM | last post by:
I am using this code to set up the splash screen startup time. Protected Overrides Function OnInitialize( _ ByVal commandLineArgs As _ System.Collections.ObjectModel.ReadOnlyCollection(Of...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.