C# keypress doesn't capture 'delete' key

The reason for this is that the KeyPress event sends a character to the control based upon the character-key you press. However, as you'd expect, the delete key does not represent a character and is thus a non-character key.

Therefore using the KeyPress event will do nothing as you have noticed. You should use the KeyDown or KeyUp Events, either of which will work absolutely fine. The nuance being whether you want your event to fire upon pressing, or letting go of a key.


You'll want to use the KeyDown event for this.


Use keyDown instead; keyPress is something like a full keyDown + keyUp

Tags:

C#

Winforms