我正在使用登录系统,我已经完全正常工作了。我从另一个网站获得了这段代码:
MessageBox.Show((found ? "Password" : "Username") + " incorrect")
但我不确定它的实际含义及其作用。
这是我的完整代码:
namespace frmSplashScreen
{
public partial class frmLogin : Form
{
public frmLogin()
{
InitializeComponent();
StartPosition = FormStartPosition.CenterScreen;
}
int signUpPressed = 0;
bool found = false;
private void button1_Click(object sender, EventArgs e)
{
string[] userdetails = File.ReadAllLines(AppDomain.CurrentDomain.BaseDirectory + "UserDetails.txt");
foreach (string user in userdetails)
{
string[] splitDetails = user.Split(':');
Login.username = splitDetails[0];
Login.password = splitDetails[1];
if (txtUsername.Text == Login.username)
{
if (txtPassword.Text == Login.password)
{
MessageBox.Show("Welcome " + Login.username);
this.Hide();
frmMainMenu menu = new frmMainMenu();
menu.Show();
return; // we're done here, so return instead of break
}
found = true;
break; // we're not gonna find this username again, so might as well quit the loop
}
}
MessageBox.Show((found ? "Password" : "Username") + " incorrect");
}
非常感谢任何帮助,谢谢。
答案 0 :(得分:0)
这是此代码的简短版本
var message = "";
if (found) {
message = "Password "+ " incorrect";
} else {
message = "Username "+ " incorrect";
}
MessageBox.Show(message)