使用回车键控制鼠标焦点

实现效果:

  

知识运用:

  KeyEventArgs类的KeyData属性

  public Keys KeyData {get;}  //获取KeyDown或KeyUp事件的键数据

  控件的Focus方法

  public bool Focus()  // 为控件设置输入焦点

实现代码:

        private void txtUser_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
                txtPwd.Focus();
        }
        private void txtPwd_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
                btLogin.Focus();
        }

  

原文地址:https://www.cnblogs.com/feiyucha/p/10321765.html