[英]c# simple login form
我正在尝试制作一个小的登录表单。 我收到名为 } 的错误。
private void button2_Click(object sender, EventArgs e)
{
String username = "motify";
String password = "0w0";
if ((textBox1.Text == username) && (textBox2.Text == password))
MessageBox.Show("Welcome back, Guest!", "NetChecker 0.5");
this.Hide();
Form1 frm2 = new Form1();
frm2.ShowDialog();
else
MessageBox.Show("Hit the 'How to login?' button to get login details!", "NetChecker 0.5");
}
}
}
完整的login.cs: https://pastebin.com/LXkBt9eC
尝试使用这个。 编码时使用适当的缩进。 谢谢。
private void button2_Click(object sender, EventArgs e)
{
String username = "motify";
String password = "0w0";
if ((textBox1.Text == username) && (textBox2.Text == password))
{
MessageBox.Show("Welcome back, Guest!", "NetChecker 0.5");
this.Hide();
Form1 frm2 = new Form1();
frm2.ShowDialog();
}
else
{
MessageBox.Show("Hit the 'How to login?' button to get login details!", "NetChecker 0.5");
}
}
您还没有打开 if 语句的括号:
if ((textBox1.Text == username) && (textBox2.Text == password))
{ //This bracket
MessageBox.Show("Welcome back, Guest!", "NetChecker 0.5");
this.Hide();
Form1 frm2 = new Form1();
frm2.ShowDialog();
}// And this bracket
else
MessageBox.Show("Hit the 'How to login?' button to get login details!", "NetChecker 0.5");
if 语句执行它后面的代码行,如果您使用括号 {} 可以包装多行以由 if 语句执行,那么您可以在这些括号之后使用 else 语句。
在您的此代码中
private void button2_Click(object sender, EventArgs e)
{
String username = "motify";
String password = "0w0";
if ((textBox1.Text == username) && (textBox2.Text == password))
MessageBox.Show("Welcome back, Guest!", "NetChecker 0.5");
this.Hide();
Form1 frm2 = new Form1();
frm2.ShowDialog();
else
MessageBox.Show("Hit the 'How to login?' button to get login details!","NetChecker 0.5");
}
如果使用'{}'大括号,请写,因为如果你只有一个语句,那么只有你可以写没有花括号。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.