Reputation: 1303
On start of my Application Login Form
comes up I have simply stored username and password and compared for validating user, if user is valid than MDIparent Form
gets opened, Now I want to create logout
for this Application. How I can do this?
When I searched I Found That I can do this on FormClosing Event or FormClosed Event but what code should be written in that and for which form, only Dispose();
is enough or something more?
What if I want Login Form
to get displayed back?
Showing MDI Form after Successful Login Like this
private void login_Click(object sender, EventArgs e)
{
//if password true then send true
bool value = namePasswordEntry(getHashedUserName, txtUserName.Text, getHashedPassword, txtPassword.Text);
if (value ==true)
{
MessageBox.Show("Thank you for activation!");
this.Hide();
Form2 pfrm = new Form2(txtUserName.Text);
pfrm.ShowDialog();
}
else
{
MessageBox.Show("Invalid LoginName or Password..");
}
}
Upvotes: 0
Views: 16539
Reputation: 51
If anyone still needs this solution:
private void logoutButton_Click(object sender, EventArgs e)
{
this.close();
}
Upvotes: 0
Reputation: 262
Try the following codes in the form closing event
Application.Exit(); - Informs all message pumps that they must terminate, and then closes all application windows after the messages have been processed.
System.Environment.Exit(1); - Terminates this process and gives the underlying operating system the specified exit code.
Application.Restart() - Shuts down the application and starts a new instance immediately.
Source : http://msdn.microsoft.com/
Upvotes: 3
Reputation: 12459
if (value ==true)
{
MessageBox.Show("Thank you for activation!");
this.Hide();
Form2 pfrm = new Form2(txtUserName.Text);
pfrm.ShowDialog();
pfrom.Dispose(); //because user has logged out so the data must be flushed, by "Disposing" it will not be in the RAM anymore, so your hanging problem will be solved
this.Show(); //just add this line here
}
To Logout using Link Label
you just need to raise the click
event of it. Write this code in the Form2
constructor:
linkLabel1.Click += linkLabel1_Click;
and then create a method:
void linkLabel1_Click(object sender, EventArgs e)
{
this.Close();
}
Upvotes: 0
Reputation: 245
You Should try this on cancel button or your form closing event........................... Application.Exit();
Upvotes: 1