key press event
-
Hi how can i use key press event in c#
-
Hi how can i use key press event in c#
Hi You can add for each component of the form a key_Down Event for example : the form is called xxx private: System::Void xxx_KeyDown(System::Object * sender, System::Windows::Forms::KeyEventArgs * e) { if(e->get_KeyCode() == 27 ) { // If the key ESC ... // Traitement } if (e.KeyChar == (char)Keys.Return) { // ENTER Key ... // Traitement } }
-
Hi You can add for each component of the form a key_Down Event for example : the form is called xxx private: System::Void xxx_KeyDown(System::Object * sender, System::Windows::Forms::KeyEventArgs * e) { if(e->get_KeyCode() == 27 ) { // If the key ESC ... // Traitement } if (e.KeyChar == (char)Keys.Return) { // ENTER Key ... // Traitement } }
thank u sir But i do not want write seperate keypress event for each control of form . i want only a single for all control
-
thank u sir But i do not want write seperate keypress event for each control of form . i want only a single for all control
Create a generic handler like so:
private void KeyPress(object sender, KeyEventArgs e)
{
// Do your stuff here
}Then assign all the event handlers to this method, i.e. in the Properties window select the Events tab, if you select the KeyPress event then a combobox should appear, select the KeyPress method and that event handler will be bound to the above function. Repeat for all the controls you want bound.
Just Google it. Failing that try phoning :bob:
-
thank u sir But i do not want write seperate keypress event for each control of form . i want only a single for all control
Set
KeyPreview
property of your form true and register to theKeyPress
event of your form.
"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