就是这样的。你的按钮是submit的就行了

解决方案 »

  1.   

    private void txtName_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    if (this.txtName.Text.Length ==0 && e.KeyValue ==8)
    {
    this.txtName.Focus ();
    }
    if(e.KeyValue ==13 && this.txtName.Text.Trim().Length !=0 )
    {
    this.txtPassWord.Focus();
    }
    } private void txtPassWord_KeyUp(object sender, System.Windows.Forms.KeyEventArgs e)
    {
    //如果密码未输入
    if (this.txtPassWord.Text.Length ==0 && e.KeyValue ==8)
    {
    this.txtName.Focus ();

    }
    if(e.KeyValue==13 && this.txtPassWord.Text.Trim().Length !=0 && this.txtName.Text.Trim().Length!=0)
    {
    //验证数据库;
    }

    }
    这个代码已经成功的应用项目中
      

  2.   

    web:
    直接写该Button的Click事件。
    Win:
    Form.AcceptButton 属性
    获取或设置当用户按 ENTER 键时所单击的窗体上的按钮