[英]How to activate a button by pressing a specific key on the keyboard?
嘿,我對編程還很陌生,我想知道如何通過按指定的鍵來激活 Windows 窗體中的按鈕,謝謝。
我嘗試這樣做:
private void Form_KeyUp(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.A)
{
btn_A.PerformClick();
e.Handled = true;
}
}
但我似乎無法讓它發揮作用。 請注意,我對這一切都很陌生,所以提前道歉。
您是否嘗試將KeyPreview
設置為true
?
也許更容易。 創建表單的 KeyPress-Event 並測試特定鍵:
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
//Test for Specific Key
if(e.KeyChar == (char)Keys.Enter)
{
//Do Stuff like:
button1.Enabled = true
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.