Solved

Login form

Posted on 2009-07-01
6
194 Views
Last Modified: 2012-05-07
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
Comment
Question by:thenrich
6 Comments
 
LVL 40

Expert Comment

by:Kyle Abrahams
ID: 24754990
In windows forms?  

You can do a Form1.Hide and Form2.show
0
 
LVL 5

Author Comment

by:thenrich
ID: 24755033
The problem with that is that the application never closes then.
0
 
LVL 15

Expert Comment

by:jinal
ID: 24755108
For exit out of application use Application.Exit()

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


0
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

 
LVL 15

Expert Comment

by:jinal
ID: 24755200
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
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 500 total points
ID: 24755267
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
 
LVL 5

Author Closing Comment

by:thenrich
ID: 31598791
I jumped the gun - I like this idea better
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
No Data for DropDown List 2 28
How to seperate number and letters from a string 3 22
SSRS 2016 Rendering HTML tables 3 31
Need syntax help building hyperlink 2 27
Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
1.0 - Introduction Converting Visual Basic 6.0 (VB6) to Visual Basic 2008+ (VB.NET). If ever there was a subject full of murkiness and bad decisions, it is this one!   The first problem seems to be that people considering this task of converting…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question