How do I make a Button "active" for the Enter Key?

F

felecha

I'm something of a rookie at .Net. I know I can set TabIndex for
controls in a GroupBox, and tab my way over to a button so it's
"Active" and will be clicked by hitting the Enter key.

But isn't there some way of setting it to the same state? I've built
a very simple login for a tabpage in a tab control, so you enter a
name and password and click the "login" button, which queries a
database to validate you. someone told me it's "correct" programming
to make it so that the user only has to complete his entry of name
and password and then immediately hit Enter and the button should be
in the active state for that without having to do one more tab-over.

I looked in the All Members in the online Help and couldn't see what I
wanted.

Thanks
 
K

Ken Tucker [MVP]

Hi,

Set the forms acceptbutton to the button you want to be clicked when
you press enter.

Ken
 
H

Herfried K. Wagner [MVP]

* (e-mail address removed)-spam.invalid (felecha) scripsit:
I'm something of a rookie at .Net. I know I can set TabIndex for
controls in a GroupBox, and tab my way over to a button so it's
"Active" and will be clicked by hitting the Enter key.

But isn't there some way of setting it to the same state? I've built
a very simple login for a tabpage in a tab control, so you enter a
name and password and click the "login" button, which queries a
database to validate you. someone told me it's "correct" programming
to make it so that the user only has to complete his entry of name
and password and then immediately hit Enter and the button should be
in the active state for that without having to do one more tab-over.

Assign the button to the form's 'AcceptButton' property.
 
F

felecha

Form.AcceptButton works just great and it was easy to understand how
to use it.

I was looking and looking but if what you're looking for is not there
but somewhere else ...

Thanks to all, this is a big help

F
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top