ses41 Posted November 28, 2002 Posted November 28, 2002 This should be simple, but I can not figure it out. I have about 100 textbox on a form. The users of this form will be use to having the "enter" key to move on to the next item. The "tab" key performs this function fine, but the users will complain if they do not have the "enter" key. Can anyone help me with simple code that would be independent of the textbox, that when the "enter" key is pressed, it performs the function of the tab key. I have been able to get it to work for an individual textbox, but I don't want to repeat the code 100 times. Quote
wyrd Posted November 28, 2002 Posted November 28, 2002 First you need to set the form's KeyPreview property to True. Then you can easily catch all keys being pressed in the OnKeyDown event and evaluate them. Here's the code that changes the focus to the next control when the user hits Enter from within a TextBox; Protected Overrides Sub OnKeyDown(ByVal e As System.Windows.Forms.KeyEventArgs) Dim ctl As Control = Me.ActiveControl If TypeOf ctl Is TextBox And e.KeyValue = Keys.Enter Then Me.SelectNextControl(ctl, True, True, True, True) e.Handled = True End If End Sub Quote Gamer extraordinaire. Programmer wannabe.
ses41 Posted November 29, 2002 Author Posted November 29, 2002 Thanks so much for the help. I was on the right track, but just couldn't get it done. .NET is a lot different than VB6. Quote
*Gurus* divil Posted November 29, 2002 *Gurus* Posted November 29, 2002 I never even knew of that method, wyrd. Just goes to show you learn something new every day. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
*Gurus* Derek Stone Posted November 29, 2002 *Gurus* Posted November 29, 2002 I have to be honest, either did I. Quote Posting Guidelines
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.