Using the ENTER button on a form

tehon3299

Centurion
Joined
Jan 6, 2003
Messages
155
Location
Liverpool, NY
Hey -

I was wondering how you can set a form so that when the user presses the 'ENTER' button, it will simulate them clicking a button on the form. For example, they input data into a textbox and hit enter instead of having to click the Submit buttom.
 
Set the Form's AcceptButton property to a button control on the form.

This won't work when some controls have focus, such as a multi-line TextBox. But then, you wouldn't want Enter to press a button in that case :)

-Nerseus
 
There is no option on the form's properties for AcceptButton. I put frmExample. and the AcceptButton is not a property for it. Am I doing something wrong? The property is on the form and not the actual button right?
 
Set it in the designer. frmExample is the name of your form class, not an instance of the class itself so you won't be able to access any instance properties like that from code unless you actually have an instance to work with.
 
Where in the designer do I set it? I remember in VB 6 there was a default button for the form, but I do not see where I set it in the designer in VB .NET.

Thanks
 
You highlight the form itself (not the button) and there is an AcceptButton in the propertygrid. In the dropdown list for that property will be all the buttons on the form.
 
Back
Top