-
Login Form
Hi,
In my application, I have given the user the option of using a login form in order to password protect his application, if he chooses to use the form, then a simple login form pops up right after the splash screen and asks for a password, if he answers the right password then the main form opens up...
My problem is that I set the mainform as my startup form and in the load event I set it to check wether the user checked the option (the boolean is stored in the database) for the login form, if he did then the login form pops up asking for a password, everything works fine until he presses cancel, I set it to close the main form and the login form as soon as he presses cancel but for some reason the main form still executes the remaining code in the load event, which i do not want, is there no way to tell vb that as soon as he presses cancel in the login form to immediately close the application instead of having continue the loading of the main form?
Code:
If settingsDataSet.settings.Rows(0)(20).ToString = "true" Then
Login.ShowDialog()
if Login.Verify = false then
me.close()
else 'Continue LOAD Code in Main Form
-
Re: Login Form
In your login form, when the user clicks on the cancel key your code should look something like this:
Code:
Private Sub Cancel_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Cancel.Click
Me.Close()
frmMainForm.Close()
End Sub
So when the user clicks on the cancel button, the logon screen and the main form both close.
Computerman :)
-
Re: Login Form
Thanks for the reply,
I've tried doing the me.close and mainFrm.close in the cancel button but it still runs all the code after the login.showdialog() in the mainform. I think it's because once I close the Login form it automatically goes back to the mainform and runs all the code after the login.showdialog() even if the form has been closed from the login form. How can the mainform still run even after I've closed from another form.
If I put me.close as the first thing in the LOAD event of the mainform, it still loads everything after the me.close, how can that be possible?
-
Re: Login Form
If you check on the documentation for .ShowDialog, you'll see that it returns a type DialogResult. If you have your form return the appropriate value (OK or Cancel), then you can use an if statement....
Code:
If Login.ShowDialog() = DialogResult.OK Then
'Continue with the load stuff
Else
Me.Close
End If
-tg