0

在我的应用程序启动时,我Login Form只存储了用户名和密码并比较了验证用户,如果用户有效而不是MDIparent Form打开,现在我想logout为这个应用程序创建。我怎么能做到这一点?

当我搜索时,我发现我可以在 FormClosing Event 或 FormClosed Event 上执行此操作,但是应该在其中编写什么代码以及对于哪种形式,Dispose();仅够还是更多?

如果我想Login Form重新显示怎么办?

成功登录后显示 MDI 表单 像这样

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..");
            }       
        }
4

4 回答 4

3

在表单关闭事件中尝试以下代码

应用程序.Exit() ; - 通知所有消息泵它们必须终止,然后在处理完消息后关闭所有应用程序窗口。

System.Environment.Exit(1) ; - 终止此进程并为底层操作系统提供指定的退出代码。

Application.Restart() - 关闭应用程序并立即启动一个新实例。

来源:http: //msdn.microsoft.com/

于 2013-09-02T07:20:37.533 回答
1

您应该在取消按钮或表单关闭事件上尝试此操作.......................Application.Exit();

于 2013-09-01T06:42:12.803 回答
0
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   
        }

要使用注销Link Label,您只需要引发click它的事件。在构造函数中写下这段代码Form2

linkLabel1.Click += linkLabel1_Click;

然后创建一个方法:

void linkLabel1_Click(object sender, EventArgs e)
    {
        this.Close();
    }
于 2013-09-01T06:55:42.943 回答
0

如果有人仍然需要这个解决方案:

private void logoutButton_Click(object sender, EventArgs e)
{

   this.close();

}
于 2021-09-15T13:44:22.430 回答