-
November 8th, 2012, 01:00 PM
#1
Unloading Forms.
Hello everyone.
I have winforms app with a login form in which the user enters a user Id and a password. After the correct user id and password is entered, the main form is displayed. When the main form is closed the Login form is still there. I need to get rid of the login form. I haven't been able to figure out how to do this. How do I get to the the Main Form's closing or unloading event? And when I am able to get to this event what do I type to close the login form?
-
November 8th, 2012, 01:59 PM
#2
Re: Unloading Forms.
When do you show the "Login" form.? Post some code please.
Normally, I would do it like this in the main form Initialization code, or in a controlling class.
dim fLogin as new frmLogin
fLogin.ShowDialog();
isLoggedin = fLogin.WasSuccessfulLogin;
fLogin.Hide();
fLogin = null;
-
November 8th, 2012, 02:10 PM
#3
Re: Unloading Forms.
Hi Sotoasty.
I was so messed up that I didn't have any code to show. What I ended up doing was hiding the login form. But that alone wasn't good enouh becuase when I closed the main form Visual Studio had the Blue square (stop debugging) icon lit up. The program was still running. So I added a Form_Closing event by using the lighting bolt and added Application.Exit. So that took care of the running program. It all works now. Thanks.
in the login form
Code:
private void cmdLogin_Click(object sender, EventArgs e)
{
if (txtUserID.Text.ToLower() == "guest" && txtPassword.Text.ToLower() == "password")
{
frmMain frmObj = new frmMain();
frmObj.Show();
this.Hide();
}
else
{
MessageBox.Show("Login incorrect: UserID = guest and password is password");
txtUserID.Text = "";
txtPassword.Text = "";
txtUserID.Focus();
}
}
in the main form
Code:
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
{
Application.Exit();
}
-
November 8th, 2012, 03:25 PM
#4
Re: Unloading Forms.
To me, this is the correct way to do it.
Startup.zip
-
November 8th, 2012, 03:41 PM
#5
Re: Unloading Forms.
I just took a look at that code. That was great. I'll definitly use this approach. Super thank you very much.
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
|