private void button1_Click(object sender, EventArgs e)
{ string userid = "asdfjkl";//定义一个用户名
string password = "123";//定义密码 if (txtUserId.Text == userid && txtpwd.Text == password)
{ // MessageBox.Show("登陆成功!");
this.Hide();
Form1 form = new Form1();
form.Show();
}
else
{
MessageBox.Show("错误,你还可以输入"+(2-count)+"次!");
count = count + 1;
}
if (count == 3)
this.Close();
}
private void denglu_KeyPress(object sender, KeyPressEventArgs e)
{
if (e.KeyCode == Keys.Return) ;
{
button1_Click();
}
}
我想在这个窗体任何时候按回车键,都对账号和密码进行判断,而怎么判断,就写在button1_Click()里面.我在一些网上看到,要写键盘事件,必须先写一段类似这样的语句
button1. KeyUp += new Syetem.Windows.Froms. KeyEventHandler(button1_KUp);但是貌似不写也可以运行...
{
if (e.KeyCode == Keys.Return) ;
{
this.button1.PerformClick(); }
}