keyup/keypress event for forms
-
How would i go about assigning the F12 key to focus on a textbox within a form? Meaning when a form is active, if the f12 key is pressed (doesn't matter which component is active) the focus will be set to a certain textbox. I know how to set the event when a certain component is active, but if i want to set a global keyup event, how would i do so? Here is the code for a textbox keyup: this.textBox_units.KeyUp += new System.Windows.Forms.KeyEventHandler this.textBox_units_EnterKeyPressed); private void textBox_units_EnterKeyPressed(object sender, System.Windows.Forms.KeyEventArgs e ) { if(( e.KeyCode == Keys.Enter ) || ( e.KeyCode == Keys.Return )) { this.textBox_upc.Focus(); } }
-
How would i go about assigning the F12 key to focus on a textbox within a form? Meaning when a form is active, if the f12 key is pressed (doesn't matter which component is active) the focus will be set to a certain textbox. I know how to set the event when a certain component is active, but if i want to set a global keyup event, how would i do so? Here is the code for a textbox keyup: this.textBox_units.KeyUp += new System.Windows.Forms.KeyEventHandler this.textBox_units_EnterKeyPressed); private void textBox_units_EnterKeyPressed(object sender, System.Windows.Forms.KeyEventArgs e ) { if(( e.KeyCode == Keys.Enter ) || ( e.KeyCode == Keys.Return )) { this.textBox_upc.Focus(); } }
Register to the
KeyUp
event of your form and set itsKeyPreview
propertytrue
.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
-
Register to the
KeyUp
event of your form and set itsKeyPreview
propertytrue
.
"Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning." - Rick Cook
works like a charm thanks :D