我有2个表单,登录(Form2)和Main(Form1)表单。我想在输入正确的用户名和密码后加载Main表单,同时隐藏/关闭登录表单。
private void button1_Click(object sender, EventArgs e)
{
string username = "admin";
string password = "admin";
if ((textBox1.Text == username) && (textBox2.Text == password))
MessageBox.Show("Login Successful");
else
MessageBox.Show("Invalid Login");
}
答案 0 :(得分:0)
如果登录成功,请先隐藏Login(Form2)
表单,然后显示Main(Form1)
表单
private void button1_Click(object sender, EventArgs e)
{
string username = "admin";
string password = "admin";
if ((textBox1.Text == username) && (textBox2.Text == password))
{
this.Visible=false;
Form1 form1 = new Form1();
form1.show();
}
else
{
MessageBox.Show("Invalid Login");
}
}
答案 1 :(得分:0)
试试这个:
this.Visible=false;
Form1 form1 = new Form1();
form1 .ShowDialog(this);
答案 2 :(得分:0)
private void LoginButton_Click(object sender, EventArgs e)
{
string username = usernameTextBox.Text ;
string password = passwordTextBox.Text ;
if (checkDatabaseForValidDetails(username,password))
{
this.Visible=false;
Form1 formObject = new Form1();
formObject.show();
}
else
{
MessageBox.Show("Login Failed");
}
}