Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Winform Splash Screen - VB.NET - Timer

I have a splash screen on the application and on that 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

Interval on the timer 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 breakpoint here but it doesn't seem to hit this breakpoint. I uncommented Me.Refresh()

Splash screen is closing. Then Login is shown with a continue button. When you click continue button

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

No window shows up and the application is hanging. Any inputs will be greatly appreciated.

like image 470
kalls Avatar asked Jan 24 '12 20:01

kalls


1 Answers

I would suggest using the built in Splash Screen that is provided by Visual Studio:

Go to the "Projects" menu and select "Add Windows Form" and select the Splash Screen template:

enter image description here

Then in the Project's Application settings, select that form to be the Splash screen:

enter image description here

Your start up form should be your login form, not the splash screen form.

Update:

Click on the "View Application Events" button on the last image from your My Project's Application 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 5000 milliseconds, or 5 seconds.

like image 125
LarsTech Avatar answered Oct 07 '22 01:10

LarsTech