|
-
Apr 4th, 2005, 04:10 PM
#1
Thread Starter
Fanatic Member
Splash Screen [RESOLVED]
Hello,
I am trying to build a splash screen for my application. So far I have in my Startup sub:
Code:
MyThread = New Threading.Thread(AddressOf ShowSplashScreen)
MyThread.Name = "Splash Screen"
MyThread.Start()
And the sub:
Code:
Public Sub ShowSplashScreen()
Splash = New SplashForm
Splash.Show()
'Only when I put MessageBox.Show("Hello") does this form show
End Sub
And in the main form load event:
Why is it that the splash form only shows when I show a message box?
Can anybody tell me what I am doing wrong?
Last edited by cpatzer; Apr 20th, 2005 at 12:48 PM.
In life you can be sure of only two things... death and taxes. I'll take death.
-
Apr 4th, 2005, 05:07 PM
#2
Re: Splash Screen
Probably because you're terminating the new Thread as soon as your form is loaded.
There are a number of way to do this, one tried and true method is to simply use a Timer, i.e.
Splash Form:
VB Code:
Public Class frmSplash
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
Friend WithEvents Timer1 As System.Windows.Forms.Timer
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Me.components = New System.ComponentModel.Container
Me.Timer1 = New System.Windows.Forms.Timer(Me.components)
'
'frmSplash
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "frmSplash"
Me.Text = "frmSplash"
End Sub
#End Region
Private Sub frmSplash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
Timer1.Interval = 5000 ' Approx. 5 Seconds.
Timer1.Enabled = True
End Sub
Private Sub frmSplash_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Click
Me.Close() ' Close when the Splash Screen is Clicked
End Sub
Private Sub Timer1_Tick(ByVal sender As Object, ByVal e As System.EventArgs) Handles Timer1.Tick
Timer1.Enabled = False
Me.Close() ' Close the Splash Screen after the time has elapsed
End Sub
End Class
Main Form:
VB Code:
Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form Designer generated code "
Public Sub New()
MyBase.New()
'This call is required by the Windows Form Designer.
InitializeComponent()
'Add any initialization after the InitializeComponent() call
End Sub
'Form overrides dispose to clean up the component list.
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'Required by the Windows Form Designer
Private components As System.ComponentModel.IContainer
'NOTE: The following procedure is required by the Windows Form Designer
'It can be modified using the Windows Form Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
Me.ClientSize = New System.Drawing.Size(292, 266)
Me.Name = "Form1"
Me.Text = "Form1"
End Sub
#End Region
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim splash As New frmSplash ' Create a new Splash Form Instance
Me.AddOwnedForm(splash) ' Make the Splash Form a Child Form of this Form (so it appears over it)
splash.Show() ' Display the Splash Form
End Sub
End Class
Regards,
- Aaron.
-
Apr 4th, 2005, 05:16 PM
#3
Thread Starter
Fanatic Member
Re: Splash Screen
The reason for that is that my application is rather large and requires quite a bit of time to load on slower machines. What I am looking to do is something like Adobe's Acrobat Reader or Photoshop. Load the splash screen first in new thread while main form is background loading. Then when the main form is loaded it closes the splash screen. Any ideas?
Thanks.
In life you can be sure of only two things... death and taxes. I'll take death.
-
Apr 4th, 2005, 06:06 PM
#4
Re: Splash Screen
You can use the code I posted, just remove the Timer and close the form after doing eveything you do in your forms Load event.
You my need to make a call to Application.DoEvents after showing the splash.
You don't need to start a new Thread to accomplish this.
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim splash As New frmSplash
Me.AddOwnedForm(splash)
splash.Show()
Dim i As Integer
For i = 1 To 1000
Console.WriteLine("Do Something")
Next
splash.Close()
End Sub
Regards,
- Aaron.
-
Apr 4th, 2005, 06:26 PM
#5
Thread Starter
Fanatic Member
Re: Splash Screen
That doesn’t quite do what I am looking for though as the load method is called after all of the dll's have been loaded and all of the form layout code has been hashed through.
This is the part that takes the time, not any routine that I have of my own.
That's why I was trying to do it with a separate thread in the startup sub so that the splash screen gets launched before any other code is executed, thus spanning the bridge in time between user double clicking on the program and the application actually loading.
Thanks.
In life you can be sure of only two things... death and taxes. I'll take death.
-
Apr 19th, 2005, 06:22 PM
#6
Thread Starter
Fanatic Member
Re: Splash Screen {UNRESOLVED}
Hate to do this but still no luck with this. Does anybody have any idea how to create a splash screen simlar to Microsoft Outlook or Adobe Reader...?
It needs to load first before any other code is executed or parsed.
Thanks.
In life you can be sure of only two things... death and taxes. I'll take death.
-
Apr 19th, 2005, 07:39 PM
#7
Re: Splash Screen
Try this instead:
In your "Splash Screen" Form Add the Following:
VB Code:
Private Shared _SplashScreen As frmSplashScreen
Public Shared Sub ShowSplashScreen()
If Not _SplashScreen Is Nothing Then
CloseSplashScreen()
End If
_SplashScreen = New frmSplashScreen
_SplashScreen.Show()
End Sub
Public Shared Sub CloseSplashScreen()
If Not _SplashScreen Is Nothing Then
Try
_SplashScreen.Close()
_SplashScreen = Nothing
Catch
End Try
End If
End Sub
Assuming your splash screen form is called frmSplashScreen you'd make
your startup object Sub Main which would be in a module:
VB Code:
Module modStartup
Sub Main()
frmSplashScreen.ShowSplashScreen()
Application.Run(New Form1) ' Where "Form1" is the main form that takes a while.
End Sub
End Module
To close the SplashScreen, do so in at the end of the main form's
Load event, i.e.
VB Code:
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i As Integer = 1 To 5000
' Simulate a load delay
Console.WriteLine(i)
Next
frmSplashScreen.CloseSplashScreen()
End Sub
Regards,
- Aaron.
-
Apr 20th, 2005, 12:43 PM
#8
Thread Starter
Fanatic Member
Re: Splash Screen
Aaron,
Ok great, I had to make some changes but was able to get it to work. Your example worked except that the SplashForm would not show any controls just white space where the controls should have been. I was able to get around this by using ShowDialog instead of Show in the ShowSplashScreen sub.
This though introduced a new problem, code execution stopped in the StartUp sub. To get around this I started a new thread:
VB Code:
SplashScreenThread = New System.Threading.Thread(AddressOf SplashScreen.ShowSplashScreen)
SplashScreenThread.Start()
This works great and accomplished just what I needed.
Thank you for your help!!!

**Edit**
If you use this you will also need to bring to front the main form after the SplashScreen form closes.
VB Code:
Private Sub SplashScreen_Closing(ByVal sender As Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles MyBase.Closing
MainForm.BringToFront()
End Sub
Last edited by cpatzer; Apr 20th, 2005 at 12:46 PM.
In life you can be sure of only two things... death and taxes. I'll take death.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|