I’m coding a splash screen in VB.Net that displays for 3 seconds then shows a login screen. But the splash shows up even when login shows and I have told the splash to hide. Here is my code:
Public Class frmSplash
Private Sub frmSplash_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Me.Show()
System.Threading.Thread.Sleep(3000)
Me.Hide()
frmLogin.Show()
End Sub
End Class
Calling
Thread.Sleepin the UI thread will freeze your program.Also, the Load event fires before the form is shown, so you’re calling
Hidebefore the form is shown in the first place.You need to add a Timer component to the form, set its
Intervalto3000, and callClosein itsTickevent. Then, call the timer’sStartmethod in the formsShownevent.