Does the KeyDown KeySuppress cancel KeyUp event?

.net, c#, events, keyboard-events, winforms

Solution

No, `e.SuppressKeyPress = true` will just ignore the `Enter` key (it won't go to the next line and Text property of the textbox won't be changed) and e.Keycode will be visible in the `KeyUp`. Therefore suppressing the key in the `KeyDown` doesn't affect the `KeyUp` event and your code should work. The `UpdateState` will be called when you hit `Enter` button in the `TextBox`. You can try this code to check it:

        private void txtAnalogValue_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.A)
            {
                e.SuppressKeyPress = true;
            }
        }

        private void txtAnalogValue_KeyUp(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.A)
            {
                MessageBox.Show("Up");
            }
        }

Problem

Let's say I've got this: ``` private void txtAnalogValue_KeyDown(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { //Non-numeric key pressed => prevent this from being input into the Textbox e.SuppressKeyPress = true; } } ``` and this: ``` private void txtAnalogValue_KeyUp(object sender, KeyEventArgs e) { if (e.KeyCode == Keys.Enter) { try { UpdateState(double.Parse(((TextBox)sender).Text)); } catch (Exception ex) { ((TextBox)sender).Text = ioElement.StateVal.ToString("0.00"); } } } ``` I know this code doesn't make a lot of sense, it's just test. The question is: Will the e.SuppressKeyPress = true in KeyDown event have affect on KeyUp event, so the Enter key will not be accepted?

Original source