Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / July 2006

Tip: Looking for answers? Try searching our database.

Make Enter key act like Tab key

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
BobRoyAce - 12 Jul 2006 06:35 GMT
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/>


Rate this thread:







Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.