A good memory is not as bad as a pen. I did not agree with this sentence before. Now many things have been forgotten without being touched for a while. So now I have recorded them, there may not be very detailed instances, but only the core part.
C # The Form class of winform has the keypreview attribute, which can receive keyboard event registration for controls in the form.
The form and control have three events: keydown, keyup, and keypress. Each event has the keyeventargs parameter passed in. You only need to judge the keychar of the input parameter, framework provides the keys enumeration to represent keys on the keyboard.
Core judgmentCodeAs follows:
1. Single-key judgment
If (E. keycode = keys. delete)
{
// Processing logic
}
2. Combined creation judgment:
If (E. modifiers. compareto (Keys. Control) = 0 & E. keycode = keys. delete)
{
// Processing logic
}