Hey there,
i have a login form, once the users logs in i want to get rid of this form, dispose of it, and open the main application form.
how do i go about doing this
Printable View
Hey there,
i have a login form, once the users logs in i want to get rid of this form, dispose of it, and open the main application form.
how do i go about doing this
HI,
Assuming the main application form will remain open thereafter use a module. In the module put something like
VB Code:
Dim frmLogin As New fclsLogin (Or whatever you called it) Friend frmMain As New fclsMain (or whatever..) Public Sub Main frmLogin.ShowDialog Application.Run(frmMain) End Sub
Then make Sub main your startup object.
Either use the Close button in the title bar to close the login form or put a button on it with the code
Me.Close
If the login is not successful, use Application.Exit to avoid opening the main form. Put a test for this in the closing event of the login form.
I agree with taxes in principle but I think he is over-complicating things a bit:This way you just return OK for a successful login and anything else for a failure. There is no need to call Application.Exit or anything like that because any DialogResult other than OK will bypass the main form and the app will exit.VB Code:
Dim frmLogin As New fclsLogin (Or whatever you called it) Friend frmMain As New fclsMain (or whatever..) Public Sub Main If frmLogin.ShowDialog() = DialogResult.OK Then Application.Run(frmMain) End If End Sub
how do i get the login form to return a dialog result
Quote:
Originally Posted by Strider
Hi,
Looks like jmcilhinney has shut down for the day.
DialogResult is a property of the form. You can set it when you validate the login entry. BUT if you allow the Close button in the titlebar to be used, the form will remain open, but hidden, so you have to dispose it.
You will find that jmcilhinney's suggestion takes as much code as mine, so take your pick.
To have ShowDialog return a value you simply set the DialogResult property of the form. Doing so will hide the form and cause ShowDialog to return the value you set. As taxes pointed out, in this situation you need to Dispose the form, which I neglected because I copied and pasted the code. Note that the form does not get Disposed when displayed using ShowDialog whether the Close button is used or you set the DialogResult explicitly. The Close button simply sets the DialogResult to Cancel. Here's what I would do myself:orVB Code:
Public Sub Main Dim login As New LoginForm If login.ShowDialog() = DialogResult.OK Then login.Dispose() Application.Start(New MainForm) Else login.Dispose() End If End SubThen you just set the DialogResult property of the login form to OK for a successful login and something else otherwise. Even though it is not strictly necessary to distinguish, I'd set it to Cancel if the user cancels the login and Abort if the login fails some prescribed number of times, which is often three. You would normally assign an OK and a Cancel button to the AcceptButton and CancelButton properties of the login form. This will automatically assign Cancel to the CancelButton's DialogResult property, which in turn assigns it to the form's DialogResult property when clicked. You would then validate the credentials in the Click event handler of the OK button and set the form's DialogResult property to OK only if the login is successful.VB Code:
Public Sub Main Dim login As New LoginForm Dim loginResult As DialogResult = login.ShowDialog() login.Dispose() If loginResult = DialogResult.OK Then Application.Start(New MainForm) End If End Sub
excellent, that helps me get my head round it all, cheers guys
Application.Start not getting any where