Keyboard events KeyPress WinForm in form controls do not respond

Keyboard events KeyPress WinForm in form controls do not respond

Today, we are doing a C # WinForm form when the need to respond to the user's keyboard events on a control form.

I found a very simple KeyDown, KeyPress event in the property page controls inside, KeyUp these mouse events, see a little explanation:

KeyDown: Occurs when a key is pressed for the first time

KeyPress: After the space has focus and the user presses and releases a key occurs

KeyUp: Occurs when a key is released

Well, obviously it KeyPress the most qualified, but pressed the Delete key on your keyboard does not respond even waited a long time found KeyPress breakpoint has no access. Tried two other events KeyDown and KeyUp controls, is normal. So find the Internet to find, to find an answer, said to be in control when needed response KeyPress events, parent form of KeyPreview must be set to True.

Invalid after trying this method.

Tried other keys on the keyboard, just like KeyPress event corresponding normal letter keys, number keys, the space there Backspace, the other seems to not work. Finally the Internet to find this explanation:

KeyPress is mainly used to capture digital (note: including the Shift + sign of the number), letters (note: including capitalization), keypad, etc. In addition to F1-12, SHIFT, Alt, Ctrl, Insert, Home, PgUp, Delete, End, PgDn , outside ScrollLock, Pause, NumLock, {} menu key, start key} {ANSI character direction keys

KeyDown and KeyUp PrScrn generally can capture all the keys except the keyboard (not discussed here special special keyboard keys)

KeyPress can only capture a single character

KeyDown and KeyUp can capture key combination.

KeyPress can capture the case of a single character

KeyDown and KeyUp KeyValue captured for each single character is a value which is not determined in the case of a single character.

KeyPress does not distinguish between numeric keypad and the main character keyboard.

KeyDown and KeyUp distinguish numeric keypad and the main character keyboard.

Which PrScrn button KeyPress, KeyDown and KeyUp can not capture.

 

Guess you like

Origin www.cnblogs.com/snsnetw/p/12381392.html