C#--监控Enter和Esc事件
作者:互联网
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); } }
标签:C#,按钮,KeyDown,FrmUserLogin,--,Esc,Enter,null 来源: https://www.cnblogs.com/baozi789654/p/15840652.html