|
-
Aug 31st, 2005, 06:41 AM
#1
Thread Starter
Fanatic Member
[RESOLVED] Close previous form
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
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Aug 31st, 2005, 06:57 AM
#2
PowerPoster
Re: Close previous form
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.
Last edited by taxes; Aug 31st, 2005 at 07:03 AM.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Aug 31st, 2005, 08:01 AM
#3
Re: Close previous form
I agree with taxes in principle but I think he is over-complicating things a bit:
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
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.
-
Aug 31st, 2005, 08:03 AM
#4
Thread Starter
Fanatic Member
Re: Close previous form
how do i get the login form to return a dialog result
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Aug 31st, 2005, 10:43 AM
#5
PowerPoster
Re: Close previous form
 Originally Posted by Strider
how do i get the login form to return a dialog result
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.
Taxes
The more I learn about VB.NET the more I like dBaseIII Plus
The foregoing, whilst believed to be correct, is given without guarantee as to it's accuracy and entirely without recourse. You are required to decide for yourself whether or not it is suitable for your purposes and no liability for loss of any nature can be entertained.
-
Aug 31st, 2005, 05:44 PM
#6
Re: Close previous form
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:
VB 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 Sub
or
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
Then 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.
-
Sep 1st, 2005, 05:18 AM
#7
Thread Starter
Fanatic Member
Re: Close previous form
excellent, that helps me get my head round it all, cheers guys
Barry
Visual Studio .NET 2008/Visual Studio .NET 2005/Visual Studio .NET 2003
.NET Framework 3.0 2.0 1.1/ASP.Net 3.0 2.0 1.1/Compact Framework 1.0
SQL Server 2005/2000/SQL Server CE 2.0
If you like, rate this post
Compact Framework for Beginners
-
Jul 4th, 2007, 06:10 AM
#8
Re: [RESOLVED] Close previous form
Application.Start not getting any where
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|