- // KeyDown event of some control
- private void SomeControl_KeyDown(object sender, KeyEventArgs e)
- {
- // 1. Event is called directly after the key stroke
- // If the user hits Enter, we catch the
- // event and do our own things
- if (e.KeyCode == Keys.Enter)
- {
- // Suppress key stroke, so that
- // the control don't receives it
- e.SuppressKeyPress = true;
- // Perform something important...
- }
- }
- // KeyPress event of some control
- private void SomeControl_KeyPress(object sender, KeyPressEventArgs e)
- {
- // 2. Event is called during the key stroke
- }
- // KeyUp event of some control
- private void SomeControl_KeyUp(object sender, KeyEventArgs e)
- {
- // 3. Event is called after the key stroke
- }
- //该片段来自于http://www.codesnippet.cn/detail/230520133529.html
来源: http://www.codesnippet.cn/detail/230520133529.html