I am using Visual Studio 2005, with VB, and I have a form where I would
like pressing the Enter key to act like pressing the Tab key. In other
words, if user is on a control, and presses Enter, focus would move to
next control in tab order.

RE: Make Enter key act like Tab key by JorisZwaenepoel

JorisZwaenepoel
Wed Jul 12 01:14:02 CDT 2006

Try this:

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As
System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
If e.KeyChar = vbCr Then
SendKeys.Send("{Tab}")
e.Handled = True
End If
End Sub

Hope it helps,

Joris

"BobRoyAce" wrote:

> I am using Visual Studio 2005, with VB, and I have a form where I would
> like pressing the Enter key to act like pressing the Tab key. In other
> words, if user is on a control, and presses Enter, focus would move to
> next control in tab order.
>
>

Re: Make Enter key act like Tab key by BobRoyAce

BobRoyAce
Wed Jul 12 02:03:13 CDT 2006

Thanks Joris...What I'd like to do, though, is specify something at the
form/user control level. Otherwise, I have to remember to use code like
you gave to handle keypresses of ALL controls on the form. Any ideas?

In my old Delphi days, I believe there was like a form-level property
called KeyPreview, and, if it was set to True, the form would check
keypresses before the controls would. Then, there, I could tell the
form to process a CR as a TAB.


Re: Make Enter key act like Tab key by Marius

Marius
Wed Jul 12 02:28:12 CDT 2006

BobRoy,

This will handle it at the form level for any ctrl on the form
AFAICS KeyPreview is irrelevant

Protected Overrides Sub OnKeyPress(ByVal e As KeyPressEventArgs)
If e.KeyChar = VB.ControlChars.Cr Then
e.Handled = True
Else
MyBase.OnKeyPress(e)
End If
End Sub

HTH,
Marius.

"BobRoyAce" <broy@omegasoftwareinc.com> wrote in message
news:1152682547.902771.31690@h48g2000cwc.googlegroups.com...
>I am using Visual Studio 2005, with VB, and I have a form where I would
> like pressing the Enter key to act like pressing the Tab key. In other
> words, if user is on a control, and presses Enter, focus would move to
> next control in tab order.
>



Re: Make Enter key act like Tab key by Marius

Marius
Wed Jul 12 02:41:06 CDT 2006

Oops, forgot to paste the essential Sub,
the one that does the actual work

Protected Overrides Sub OnKeyDown(ByVal e As KeyEventArgs)
If e.KeyCode = Keys.Enter Then
MyBase.ProcessTabKey(Not e.Shift)
e.Handled = True
Else
MyBase.OnKeyDown(e)
End If
End Sub



"Marius Groenendijk" <Marius Groenendijk (Hotmail)> wrote in message
news:%23$9XwSYpGHA.3600@TK2MSFTNGP04.phx.gbl...
> BobRoy,
>
> This will handle it at the form level for any ctrl on the form
> AFAICS KeyPreview is irrelevant
>
> Protected Overrides Sub OnKeyPress(ByVal e As KeyPressEventArgs)
> If e.KeyChar = VB.ControlChars.Cr Then
> e.Handled = True
> Else
> MyBase.OnKeyPress(e)
> End If
> End Sub
>
> HTH,
> Marius.
>
> "BobRoyAce" <broy@omegasoftwareinc.com> wrote in message
> news:1152682547.902771.31690@h48g2000cwc.googlegroups.com...
>>I am using Visual Studio 2005, with VB, and I have a form where I would
>> like pressing the Enter key to act like pressing the Tab key. In other
>> words, if user is on a control, and presses Enter, focus would move to
>> next control in tab order.
>>
>
>



Re: Make Enter key act like Tab key by Herfried

Herfried
Wed Jul 12 04:29:08 CDT 2006

"BobRoyAce" <broy@omegasoftwareinc.com> schrieb:
>I am using Visual Studio 2005, with VB, and I have a form where I would
> like pressing the Enter key to act like pressing the Tab key. In other
> words, if user is on a control, and presses Enter, focus would move to
> next control in tab order.

Enter Instead of Tab
<URL:http://blogs.duncanmackenzie.net/duncanma/archive/2004/12/13/936.aspx>

--
M S Herfried K. Wagner
M V P <URL:http://dotnet.mvps.org/>
V B <URL:http://classicvb.org/petition/>