c# - How to capture Key press event for a text box? -


i have winform application has 2 text boxes , button. if control focus on of text boxes , user clicks keyboard "enter" button. button event should invoke.

the issue couldn't find textbox_keydown capture "enter" key press. in visual studio editor, keydown,keypress,keyup properties empty.

a couple things. sounds me need set acceptbutton on form button want clicked when user presses enter. handled automatically you.

second, if that's not case, need set keypreview true on form , handle processcmdkey method on form:

protected override bool processcmdkey(ref message msg, keys keydata) {     if (keydata == keys.enter)     {         //     }     else     {         base.processcmdkey(ref msg, keydata);     } } 

Comments

Popular posts from this blog

Unable to remove the www from url on https using .htaccess -