473,788 Members | 3,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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(loa dmainscm));

mainapp.Start() ;

//where

private void loadmainscm() {

SCM.frmSplash frmsplash = new frmSplash();

frmsplash.Show( );

Thread.Sleep(10 000);

}
However the 2nd form will show but the graphics and controls are not
rendered when I use Thread.Sleep(10 000); ... if I do not use
Thread.Sleep(10 000); 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 20636
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.Threadin g;

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

private System.Componen tModel.IContain er 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.Disp ose();
}
base.Dispose(di sposing);
}

#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 InitializeCompo nent()
{
this.components = new System.Componen tModel.Containe r();
this.AutoScaleM ode = System.Windows. Forms.AutoScale Mode.Font;
this.Text = "SplashScre en";
}
#endregion

private SplashScreen()
{
InitializeCompo nent();
}

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

}

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

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

private static void CloseSplashDown ()
{
Application.Exi tThread();
}

public static void CloseSplash()
{
//Need to get the thread that launched the form, so
//we need to use invoke.
MethodInvoker mi = new MethodInvoker(C loseSplashDown) ;
_splashScreen.I nvoke(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.Sh owSplash();

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.Threadin g.Thread.Sleep( 5000);

InitializeCompo nent();

//Close the splash
SplashScreen.Cl oseSplash();
}
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(loa dmainscm));

mainapp.Start() ;

//where

private void loadmainscm() {

SCM.frmSplash frmsplash = new frmSplash();

frmsplash.Show( );

Thread.Sleep(10 000);

}
However the 2nd form will show but the graphics and controls are not
rendered when I use Thread.Sleep(10 000); ... if I do not use
Thread.Sleep(10 000); 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*********@di scussions.micro soft.com> wrote in message
news:81******** *************** ***********@mic rosoft.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.Threadin g;

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

private System.Componen tModel.IContain er 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.Disp ose();
}
base.Dispose(di sposing);
}

#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 InitializeCompo nent()
{
this.components = new System.Componen tModel.Containe r();
this.AutoScaleM ode = System.Windows. Forms.AutoScale Mode.Font;
this.Text = "SplashScre en";
}
#endregion

private SplashScreen()
{
InitializeCompo nent();
}

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

}

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

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

private static void CloseSplashDown ()
{
Application.Exi tThread();
}

public static void CloseSplash()
{
//Need to get the thread that launched the form, so
//we need to use invoke.
MethodInvoker mi = new MethodInvoker(C loseSplashDown) ;
_splashScreen.I nvoke(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.Sh owSplash();

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.Threadin g.Thread.Sleep( 5000);

InitializeCompo nent();

//Close the splash
SplashScreen.Cl oseSplash();
}
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(loa dmainscm));

mainapp.Start() ;

//where

private void loadmainscm() {

SCM.frmSplash frmsplash = new frmSplash();

frmsplash.Show( );

Thread.Sleep(10 000);

}
However the 2nd form will show but the graphics and controls are not
rendered when I use Thread.Sleep(10 000); ... if I do not use
Thread.Sleep(10 000); 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
7196
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 stay up. thanks
2
1694
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 a timer on frmSplash set to 3000 ms interval - and here is its tick event : Private Sub tmrStartup_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles tmrStartup.Tick Dim frmParent As New frmParent frmParent.Show() Me.Close()
2
2109
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, the splash screen (and no other screen) is displayed for the entire run of the application. How can I disable the spalsh screen just for when an app is run as a scheduled task?
5
6412
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 splash screen interfering with msgboxes which may need to be displayed if the licence is invalid or missing I have tried in the splash form's formclosing event but it does not fire
3
2340
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 closes or I close it to allow error messages to be displayed from Licence or Database checking errors
2
2356
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 (specified in same place) causes error when it is loading and it cannot open database connection for example? Now error message will be below Splash Screen form, and it causes problem how to read error message and close it.
2
4220
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 it. I presume it only stays visible while the main form initialises. This is not long enough but I can't see how to slow it down. Should I set the splash screen using the Application settings or go back to
1
1569
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 String) _ ) As Boolean ' Set the display time to 5000 milliseconds (5 seconds). Me.MinimumSplashScreenDisplayTime = 5000 Return MyBase.OnInitialize(commandLineArgs) End Function
1
3057
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 String) _ ) As Boolean ' Set the display time to 5000 milliseconds (5 seconds). Me.MinimumSplashScreenDisplayTime = 5000 Return MyBase.OnInitialize(commandLineArgs) End Function
0
9655
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10172
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10110
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8993
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7517
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 presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6749
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5535
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4069
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3670
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.