# vb.net textbox question



## soulfly (May 29, 2004)

Hello everyone,

I have a question on vb.net and it's about textbox. I'm creating a simple windows form where i have several textbox(es) and a command button (name) save. How can I make a text accept an enter key (or return key) so that instead of clicking the command button to execute a function, i'll just have to press the enter key from the keyboard and then the function of that the command button is holding will be executed.

Any help is highly appreciated.


----------



## wildcat74 (Dec 1, 2004)

hello soulfly,
I'm at work right now so I'm not 100% sure but there should be an option somewhere in the properties for the textbox that will let you set an accept button.


----------



## Lycaon (Sep 19, 2005)

soulfly:

I'm at work, so I can't give perfect instructions, but in the textbox's KeyPress Event, you'll want to use something similar to this:

If e.KeyChar = SomeEnum.Enter Then
' Do your stuff here
End If

'SomeEnum' is the enum that comes up after you hit the = key, I can't remember the name offhand.

The only caveat here is you'll get that 'doink' sound. Back in VB6 you'd use KeyAscii=0 to 'cancel' that effect, however, I haven't figured out how to do it in .NET yet.


----------



## ssteele00 (Oct 12, 2005)

Set the FORM's 'AcceptButton' property to the button you want to get "fired" when pressing enter. The only problem in doing it this way is that you have no control over which object the user was modifying when they hit enter. It does however, silence the 'donk' and fires the choosen click event.

-Shawn


----------



## soulfly (May 29, 2004)

thanks for all your ideas. I really appreciated it.


----------



## Lycaon (Sep 19, 2005)

Ah ha, thanks


----------



## Forseti (Dec 6, 2005)

Found this "old" thread and was wondering if someone found out how to get rid of the gd stupid sound that it playes when keys.enter is pressed?

I cant use the "acceptbutton solution" because i have a form with two "sets" of textboxes who has its own buttons to be "pressed" when enter is pressed on keyboard..

I Found out an workaround for this but its uuuuugly... Create a "dummy" button and set that to acceptbutton and voila no SOUND


----------

