Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

User pressing TAB or Enter to advance to next field on a form

1 view
Skip to first unread message

eljainc

unread,
May 12, 2008, 11:37:05 AM5/12/08
to
Hello,

I have a perplexing situation. I am using Visual Studio 2005 SP1 and
have created a simple form with two or three textboxes on them. They
are not multi-line text boxes. I would like the behavior of them to
advance to the next control when Tab or ENTER is pressed. However I
cannot seem to change the property to do this. Sure I could write a
KeyDown event handler to mimic this, but why invent the wheel? Can
someone shed some insight into this? Is there another property that I
am not seeing? I have tried AcceptsTab and AcceptsReturn, but those do
not seem to have any effect on the tab/enter working.

Thanks
Mike

Ignacio Machin ( .NET/ C# MVP )

unread,
May 12, 2008, 2:22:55 PM5/12/08
to

Tab should by by default, take a look at TabIndex property.
For Enter you must use Form.ProcessCmdKey (or KeyDown event)

eljainc

unread,
May 12, 2008, 4:02:28 PM5/12/08
to
On May 12, 1:22 pm, "Ignacio Machin ( .NET/ C# MVP )"
<ignacio.mac...@gmail.com> wrote:

The TabIndex IIRC controls the order of the controls on the form that
the Tab key will
activate.

I trapped the Enter key on the KeyDown event. I'm still stuck though
as I cannot get it
to move to the next field. What am I missing here?

Ignacio Machin ( .NET/ C# MVP )

unread,
May 13, 2008, 10:26:04 AM5/13/08
to
> to move to the next field.  What am I missing here?- Hide quoted text -
>
> - Show quoted text -

Hi,

You have two options:
1- Detect which is the control with the next TabIndex and do a
Control.Focus() to it
2- See if you can "change" the key pressed from enter to TAB. You can
set KeyPressEventAgrvs.KeyChar to the correct char

0 new messages