Winform splash screen - VB.NET - Timer

I have a splash screen in the application and in this form. I have a timer.

Private Sub Splash_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load SplashTimer.Start() ' Set application title ' Set Version Me.Show() 'Me.Refresh() 'System.Threading.Thread.Sleep(2000) 'Login.ShowDialog() 'Login.AllowTransparency = True End Sub 

The timer interval is set to 5000.

  Private Sub SplashTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SplashTimer.Tick SplashTimer.Stop() Login.Show() Login.AllowTransparency = True Me.Hide() End Sub 

I set a breakpoint here, but it doesn't seem to hit that breakpoint. I uncommented Me.Refresh ()

The screensaver closes. Then Login is displayed with a continue button. When you click the continue button

 MainMenu.Show() 'this form should be shown as this is the main window of the application but it not showing. Me.Close() 'closes login window 

The window does not appear and the application hangs. Any inputs would be greatly appreciated.

+7
source share
3 answers

I would suggest using the integrated Splash screen provided by Visual Studio:

Go to the Projects menu and select "Add Windows Form" and select a splash screen template:

enter image description here

Then, in the project application settings, select this form as the Splash screen:

enter image description here

Your startup form should be your login form, not your splash screen.

Update:

Click the “View Applications” button in the last image on the “My Project” screen and add this code to set the MinimumSplashScreenDisplayTime value

 Imports System.Collections.ObjectModel Namespace My Partial Friend Class MyApplication Protected Overrides Function OnInitialize(commandLineArgs As ReadOnlyCollection(Of String)) As Boolean Me.MinimumSplashScreenDisplayTime = 5000 Return MyBase.OnInitialize(commandLineArgs) End Function End Class End Namespace 

Your splash screen will remain on the screen for 5,000 milliseconds or 5 seconds.

+13
source

Try adding a module to your program using the Public Sub Main method. Set launch options in Sub Main. Then you can do something like:

 Module Module1 Dim frmSplash As SplashScreen1 Dim frmLogin As Login Dim frmMain As MainMenu Dim splashTimer As Timer Public Sub Main() splashTimer = New Timer() AddHandler splashTimer.Tick, AddressOf TimerTick splashTimer.Interval = 5000 splashTimer.Start() frmSplash = New SplashScreen1 frmSplash.ShowDialog() frmLogin = New Login Dim result As DialogResult = frmLogin.ShowDialog If result <> DialogResult.OK Then End End If frmMain = New MainMenu frmMain.ShowDialog() End Sub Private Sub TimerTick(sender As Object, e As EventArgs) splashTimer.Stop() frmSplash.Close() End Sub End Module 

Project Settings:

+3
source

What I discovered is that timer events do not fire until the Load event / method ends. I put thread.sleep in the activated event / method and it gives me the desired result. So I'm trying to show a splash screen with several different background images, and this works great.

0
source

All Articles