- //按回车,焦点跳到密码文本框
- private void txtUserName_KeyPress(object sender, KeyPressEventArgs e)
- {
- if (e.KeyChar == '\r')
- {
- txtPassword.Focus();
- }
- }
- //按回车,直接登陆
- private void txtPassword_KeyDown(object sender, KeyEventArgs e)
- {
- if (e.KeyCode == Keys.Return)
- {
- btnOK_Click(null,null);
- }
- }
3.将窗体的AccptButton属性设置成你想要提交的那个按钮的名称就行了,不得不感叹微软实在很强!