Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 202
  • Last Modified:

Login form

I've created a login form where user types in credentials. Once the credentials are validated I want to close the login form and launch another form which would be the main application thread. What is the appropriate way to do this?
0
thenrich
Asked:
thenrich
1 Solution
 
Kyle AbrahamsSenior .Net DeveloperCommented:
In windows forms?  

You can do a Form1.Hide and Form2.show
0
 
thenrichAuthor Commented:
The problem with that is that the application never closes then.
0
 
jinalCommented:
For exit out of application use Application.Exit()

As you are Hide the for opening another form instead of hide use close form.


0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
jinalCommented:
Another solution is dont keep your LoginForm as main form.

Instread of that use another form as a mainform and in that load event of another form use loginform.showdialog()
0
 
Mike TomlinsonMiddle School Assistant TeacherCommented:
Use the Application.Startup() event instead:
http://msdn2.microsoft.com/en-us/library/t4zch4d2(VS.80).aspx

This event fires BEFORE the "Startup" Form is ever shown.  From there you can show "frmLogin" and make a decision whether the app should continue.  If login fails, you can Cancel the application without ever showing the main form.

Keep the MAIN Form as the default one in your Project Properties by setting it as the "Startup Object".  Then in Project Properties, click on the "View Application Events" button in the bottom right.  Now you can trap the Application Startup() event and prevent the default Form1 from showing by setting the e.Cancel parameter to True.
Across the top, change the Left dropdown to "(MyApplication Events)", and the Right dropdown to "Startup":
Namespace My
 
    ' The following events are availble for MyApplication:
    ' 
    ' Startup: Raised when the application starts, before the startup form is created.
    ' Shutdown: Raised after all application forms are closed.  This event is not raised if the application terminates abnormally.
    ' UnhandledException: Raised if the application encounters an unhandled exception.
    ' StartupNextInstance: Raised when launching a single-instance application and the application is already active. 
    ' NetworkAvailabilityChanged: Raised when the network connection is connected or disconnected.
    Partial Friend Class MyApplication
 
        Private Sub MyApplication_Startup(ByVal sender As Object, ByVal e As Microsoft.VisualBasic.ApplicationServices.StartupEventArgs) Handles Me.Startup
            If LoginForm.ShowDialog() = Windows.Forms.DialogResult.Cancel Then
                ' Prevent the "Startup Object" from showing...
                e.Cancel = True          
            End If
        End Sub
 
    End Class
 
End Namespace

Open in new window

0
 
thenrichAuthor Commented:
I jumped the gun - I like this idea better
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now