1,对于winform自带的Button按钮
this.cancelButton = this.button1;//设置Esc键 this.AcceptButton = this.button2;//设置Enter键
2,对于自定义的按钮
public FrmUserLogin() { InitializeComponent(); this.KeyPreview = true;//WinForm下的键盘事件(KeyPress、KeyDown)不响应的大多数原因 this.KeyDown += FrmUserLogin_KeyDown; } private void FrmUserLogin_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { this.btn_login_Click(null,null); } }