Reputation: 508
Good day guys! I have a question in VB.NET. While creating and testing my GUI for a login screen to show up the main page of the payroll system, there's this problem.
The splash screen loads normally, and the login form appear. I type my username and password (e.g. Username: Admin, Password: 12345) and login was successful. Here's the problem: When the Main Menu shows up, the Login screen appears AGAIN, which is at this time, that screen should be already closed. Did I have any problem with the use of Show, Hide, and Close?
Here's my code for the three forms.
A. Splash Screen
Public Class frmSplashScreen
Private Sub tmrSplashScreen_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrSplashScreen.Tick
Me.Hide()
frmLogin.Focus()
frmLogin.Show()
End Sub
End Class
B. Login Form (for system access)
Public Class frmLogin
Public userName As String
Public passWord As String
Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click
End
End Sub
Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click
userName = txtUsername.Text
passWord = txtPassword.Text
If userName = "Admin" And passWord = "12345" Then
MsgBox("Access Granted! Welcome to BYTE!", MsgBoxStyle.Information, "Byte EGC Payroll System")
Me.Close()
frmMainMenu.Show()
frmMainMenu.Focus()
Else
MsgBox("Access Denied!", MsgBoxStyle.Critical, "Byte EGC Payroll System")
End If
End Sub
End Class
and lastly:
C. Main Menu.
Public Class frmMainMenu
Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click
End
End Sub
Private Sub frmMainMenu_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Me.WindowState = FormWindowState.Maximized
End Sub
Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click
MsgBox("Byte" & vbCrLf & "By: JU-CHAN", vbInformation, "Byte Payroll System")
End Sub
End Class
Help is greatly appreciated. Thank you! :)
Upvotes: 0
Views: 1534
Reputation: 15813
The timer keeps ticking, causing the splash screen to reload, then hide, showing the login screen again.
Try putting this in the tmrSplashScreen tick handler:
tmrSplashScreen.Enabled = False
Upvotes: 2
Reputation: 1846
Your splash screen shouldn't be controlling when the logon form shows. A splash screen should only be used during the startup of the program when it's doing a lot of processing in the background before the program can actually start up. Just showing a splash screen for the sake of doing it will annoy end users.
Since your basic logon screen above doesn't look like it would take a lot of resources to use, a better option would be to use the flow of:
Show Logon screen
If password is successful then
- display splash screen
- load application in the background
- once application is loaded, display main window and hide splash scrfeen
Some sample code for this would be:
Module modMain
'In a module
Public frmSpl As frmSplash
Public frmMain As frmMainMenu
Public Sub Main(ByVal args() as String)
dim frmLogin as New frmLogin
'Assume frmLogin is a modal form
frmLogin.Show
'A public property set on the Login form
If frmLogin.Passed = True Then Do
'Load and display the splash screen
frmSpl = New frmSplash
frmSpl.Cursor = Cursors.WaitCursor
frmSpl.Show()
Application.DoEvents()
'If there is any code needed to run before displaying the Main Form
'do it here
frmMain = New frmMainMenu
'Begin running standard application loop for frmMainMenu
Application.Run(frmMain)
End If
End Sub
End Module
Then in frmMainMenu you would have code similar to:
Public Class frmMainMenu
Private Sub frmMainMenu_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Try
Me.Cursor = Cursors.WaitCursor
Me.SuspendLayout
Me.WindowState = FormWindowState.Maximized
'Put any other loading code needed for this form here
Catch (ex as Exception)
'Handle exceptions here
Finally
'Hide the splash screen
frmSpl.Hide()
frmSpl.Dispose()
'Display the form
Me.ResumeLayout
Me.Cursor = Cursors.Default
Me.Show
End Try
End Sub
Upvotes: 1
Reputation: 34907
I'm betting your problem is that the timer in your splash screen is still firing _tick events and bringing up the login page again.
Maybe add tmrSplashScreen.Stop()
before you hide the splash screen?
Or better yet. Get rid of the splash screen altogether, they are evil.
Upvotes: 2