改为如下:
static void Main()
{
Form2 form2=new Form2();
if(form2.ShowDialog()==DialogResult.OK)
Application.Run(new Form1());
}在登录窗体的确定按钮的CLICK事件下加入下列代码:
if (this.textBox1.Text=="user" & this.textBox2.Text=="12345")
{
this.DialogResult=DialogResult.OK;
this.Close();
}
else
{
MessageBox.Show("用户名或密码不正确,请重新输入!");
this.textBox1.Focus();
}
static void Main()
{
Form2 form2=new Form2();
if(form2.ShowDialog()==DialogResult.OK)
Application.Run(new Form1());
}在登录窗体的确定按钮的CLICK事件下加入下列代码:
if (this.textBox1.Text=="user" & this.textBox2.Text=="12345")
{
this.DialogResult=DialogResult.OK;
this.Close();
}
else
{
MessageBox.Show("用户名或密码不正确,请重新输入!");
this.textBox1.Focus();
}
Application.Run();
改为
this.Close();不过建议用DialogResult来做,即上面的方法。
static void Main()
{
Application.Run(new Form1());
}
在form1的load事件中加上:
Form2 form2=new Form2();
form2.ShowDialog();把form2的确定按钮的CLICK事件下加入下列代码:
if (this.textBox1.Text=="user" & this.textBox2.Text=="12345")
{}
else
MessageBox.Show("用户名或密码不正确,请重新输入!");
this.textBox1.Focus();