2014-07-14 47 views

回答

8

您正在尋找Form.AcceptButton財產

獲取或設置點擊,當用戶按下ENTER鍵在窗體上的按鈕。

+0

值得注意的一個非空Form.AcceptButton財產的行爲,並有一個文本框'AcceptsReturn = TRUE' –

+0

這是它。謝謝你Selman22。 –

2

你可以監聽KeyUp事件

using System.Windows.Forms; 

private void btnSubmit_KeyUp(object sender, KeyEventArgs e) 
{ 
    if(e.KeyCode == Keys.Enter) 
     MessageBox.Show("You hit the Enter key."); 
}