winform登录时,在密码框按下回车,直接登陆

  1. //按回车,焦点跳到密码文本框  
  2. private void txtUserName_KeyPress(object sender, KeyPressEventArgs e)  
  3. {  
  4.     if (e.KeyChar == '\r')  
  5.     {  
  6.         txtPassword.Focus();  
  7.     }  
  8. }  
  9. //按回车,直接登陆  
  10. private void txtPassword_KeyDown(object sender, KeyEventArgs e)  
  11. {  
  12.     if (e.KeyCode == Keys.Return)  
  13.     {  
  14.         btnOK_Click(null,null);  
  15.     }  
  16. }  
3.将窗体的AccptButton属性设置成你想要提交的那个按钮的名称就行了,不得不感叹微软实在很强!
posted @ 2014-12-24 13:47  AndSir  阅读(728)  评论(0编辑  收藏  举报
http://www.andsir.cn