I have a C# form with 5 buttons. The users enters the information and depending on the press of a function key, a specific action is performed. F9-Execute Order, F6-Save, F3-LookUp.
I have added the foolowing code:
OnForm_Load
this.KeyUp += new System.Windows.Forms.KeyEventHandler(KeyEvent);
and
private void KeyEvent(object sender, KeyEventArgs e) //Keyup Event { if (e.KeyCode == Keys.F9) { MessageBox.Show("Function F9"); } if (e.KeyCode == Keys.F6) { MessageBox.Show("Function F6"); } else MessageBox.Show("No Function"); }
but nothing happens
Thanks
You can execute a function by pressing the enter key in a field using the key event in JavaScript. If the user presses the button use the keydown to get know its enter button or not. If it enters the key then call the JavaScript function.
keypress (plural keypresses) The depression of an input key; a keystroke. (computing) The buffered electrical signal resulting from such an event, sometimes distinguished from the release.
The keypress event is fired when a key that produces a character value is pressed down. Examples of keys that produce a character value are alphabetic, numeric, and punctuation keys. Examples of keys that don't produce a character value are modifier keys such as Alt , Shift , Ctrl , or Meta .
You need to set
KeyPreview=True
for your form. Otherwise key press is swallowed by the control that has focus.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With