Capture keyboard inputs without a textbox

后端 未结 1 1237
执笔经年
执笔经年 2021-01-07 01:12

I have a application that reads data from health cards and parse them for basic info like D.O.B., Health Card #, and names. Right now, I have a textbox that takes input from

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-01-07 01:47

    If you add a key handler to the form you will not see the key presses when focus is on a control, e.g. a textbox. For the form to see the key presses even when there is a focused control, you must also enable the KeyPreview property.

    You can then add a handler for KeyDown, KeyPress and/or KeyUp on the form as you desire to receive these events.

    As you can read in the documentation to KeyPreview, if you set the Handled property to true, you can prevent the event from being subsequently sent to the focused control, i.e. you can hide certain key events from being seen by the focused control.

    0 讨论(0)
提交回复
热议问题