窗口控件執行KeyPress事件。
下面以textbox控件為例:
private void textBox1_KeyPress(object sender, KeyPressEventArgs e) { if(e.KeyChar == '\r')//或者e.KeyChar == (char)Keys.Enter { button1.Focus(); //將鼠標焦點移到Button1按鈕上 button1_Click(this, new EventArgs()); //執行按鈕事件 }
另外,也可以參考:
作者昵稱: 驚風雨
https://www.cnblogs.com/winformasp/articles/11870708.html