Question Login Form/Main Form

Simple Man

Member
Joined
Jul 7, 2010
Messages
13
Programming Experience
5-10
I've created a windows form application in vb 2010. I've got all my forms complete and now want to add a Login screen.

One the login screen, after the username/password is entered and OK is pressed, I try to open the a connection string. Obviously if the connection fails, the user has entered the incorrect credentials. If the credentials are ok, True is returned and I then open up the Main form that shows the correct items for the logged in user.

I'm having some issues when it comes to ending the application. In the properties of my application, the Startup form is Login. The shutdown mode is set to "When last form closes". After loging in successfully I open up the Main form and then close the Login form. From the Main form when a link is clicked to open up another form, I hide the Main form (frmMain.Hide) and then open up the next form (Form1). When Form1 is closed, I unhide frmMain by using frmMain.Show. If I try and close frmMain the VB is still in debug mode and I have to press the square. If I log into the program and the Main form opens up and then I close it, VB closes out of debug mode. Only if I open up a form from the Main form and close it, it's like it's opening up another frmMain but the other frmMain is still hidden. This make sense?

My thoughts to hide frmMain is so that I don't have to update the form based on the user that is logged in. I figured hiding it will be more efficient??? Maybe not. I haven't tried to close the form and reopen it yet. Just wondering if someone could explain my current issue.

Thanks.

Nick
 
Here's how I typically do it:
Show the main form with no data loaded
In the main form's Shown event I'll show the login form
If the user cancels (or closes) the login form, then I close the main form (from the Shown event still) which closes the entire app
If the user successfully logs in, then I load the data and show it in the main form

If something needs to be done to log out, I'll make sure it's done not only in a logout routine, but I make sure to do so from the FormClosing event too.
 
Thanks all for the responses. I'll use a login dialog box when the main form opens up.

Nick

I would suggest not, unless you want to give the user access to the main form even if the login fails. What's the point of even creating a main form if it's never going to be used?
 
Back
Top