简体   繁体   中英

Form keydown in C#

I use these codes to inform users when they press a button and show them in a message box that you have pressed a button. In the winform I have a button, so these codes won't working until I change button1 tabstop to false. and when I click on the button after that it won't tell users that they're pressing a button.

private void Form1_KeyDown(object sender, KeyEventArgs e)
{
   if (e.KeyCode == Keys.A)
   {
      MessageBox.Show("You have pressed A");
   }
}

These codes won't working until I change tabstop of the button to false. Help to how can I do that and let the users know when they pressed a button in any time.

Any help will be appreciated

Set the KeyPreview property of form to true from designer. It will work

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM