如果用户未能登录3次,如何关闭登录表单。我应该怎么做才能实现它?
if (user == "Admin" && pass == "Admin")
{
//if user and pass are correct
MessageBox.Show("Admin Access", "Access Granted",
MessageBoxButtons.OK, MessageBoxIcon.Information);
//will transfer to the next form
frmItems frmitem = new frmItems();
frmitem.Show();
this.Hide();
}
else
{
//to make the textbox null if the pass is wrong
txtUser.Text = "";
txtPass.Text = "";
count = 0;
count++;
//if the user or pass are wrong
MessageBox.Show("Invalid User/Passwosrd", "Access Denied",
MessageBoxButtons.OK, MessageBoxIcon.Error);
/close the program if the pass/user failed 3 times
if (count == 3)
{
MessageBox.Show("This program will close", "Access Denied",
MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
}
答案 0 :(得分:0)
现在,您正在函数内部进行,因为每次将变量设置回0时。
您只需将count的值设置为0即可定义它。希望你把你的计数变量作为全局变量。