c# - Why KeyDown event wont fire? -
my original intention in make enter event text box run btnok_click event, after several try can't make happen, tried way , try keypress key still didn't work, made these 2 simple code, still didn't work either;
private void textbox2_keydown(object sender, keyeventargs e) { if (e.keycode == keys.enter) { //enter key down //btnok_click(this, e); system.windows.forms.messagebox.show("my message here"); } } private void textbox2_keypress(object sender, keypresseventargs e) { if (e.keychar == (char)keys.return) { //enter key down //btnok_click(this, e); system.windows.forms.messagebox.show(((char)keys.return).tostring()); } }
any suggestion? read similar questions , said set isinputkey
property true can't find anywhere. use visual studio 2008
two options : 1) use key event as
public void txt_keyup(object sender, keyeventargs e) { if (e.keycode == keys.enter) { btnok_click(sender, e); // or btn.performclick(); return; } }
2) make btnok acceptbutton of form. (note : textboxes in form)
this.acceptbutton = btnok;
Comments
Post a Comment