Bind Enter key to a Button

jriggs420

New member
Joined
Apr 24, 2007
Messages
2
Programming Experience
Beginner
Sorry for the painfully obvious question here-

I just have a form with some textboxes on it, as well as a 'Submit' . I just want to make it so that hitting the 'Enter' key will have the same result as clicking the submit button. Couldn't find it on google, thanks-

JR
 
You may use the defaultbutton attribute of the form tag.

Hi,
You may use the defaultbutton attribute of the form tag.

VB.NET:
<form id="form1" runat="server" defaultbutton = "Button1">
 
ajeeshco: I believe you missed the fact that this question is posted in the compact framework category.

jriggs420: I don't understand why you would want this functionality in a compact application, but it's been years since I've used a compact device. The standard winform framework includes the AcceptButton property for the form class, but I don't think it's available in the compact framework. You could set the keyPreview property of the form to true and create a KeyUp event handler for the Form. In the event handler, if the key is the enter key, call the button's click procedure.
 
Thanks ajeeshco

@paszt - one of the mods moved my thread for some reason, I can't remember where I posted originally. The question was for a regular VB app, so where would the best place have been to post? Thanks-
 
OK, I've moved it to the Windows Forms category. Probably a mistake by another mod.

So is you're question answered using the AcceptButton property?
 
1- activate the form
2- go to property window
3- choose the ACCEPTBUTTON property and choose ur button

So Simple ......

there is another way for the forms which is not supporting the acceptbutton property
as he said that u make a sub handles keystroke
if keystrok = Enter
button_Click.perform click()
end sub

that's it
 
In the Form's Property List, change the "AcceptButton" Property' value with your submit button. So, you also can change the "CancelButton" Property
so that hitting the 'ESC' key will have the same result as clicking the cancel button.

BEST REGRADS! :)
 
Back
Top