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.
Joris Zwaenepoel - 12 Jul 2006 07:14 GMT
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
> 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.
BobRoyAce - 12 Jul 2006 08:03 GMT
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.
Marius Groenendijk - 12 Jul 2006 08:28 GMT
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.
>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.
Marius Groenendijk - 12 Jul 2006 08:41 GMT
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
> BobRoy,
>
[quoted text clipped - 16 lines]
>> words, if user is on a control, and presses Enter, focus would move to
>> next control in tab order.
Herfried K. Wagner [MVP] - 12 Jul 2006 10:29 GMT
"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>

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