How do I capture Keys.F1 regardless of the focused control on a form?

前端 未结 4 1047
旧时难觅i
旧时难觅i 2020-11-30 06:37

I used KeyDown event and some simple code like if (e.KeyCode == Keys.F1) to capture F1 is pressed on a form BUT if there are some text boxes on the form or if t

4条回答
  •  温柔的废话
    2020-11-30 06:57

    Set the form's KeyPreview to true. This will make sure the form get the keypress messages first and if you handle it, you can set e.Handled = true so it doesn't passed down to the controls.

提交回复
热议问题