How to Make the Enter Key Also a Tab Key in Visual Basic

Written by jaime avelar
  • Share
  • Tweet
  • Share
  • Pin
  • Email
How to Make the Enter Key Also a Tab Key in Visual Basic
Detect key pressed in VB.NET. (NA/PhotoObjects.net/Getty Images)

Sometimes you may want to change the function of a key on your keyboard to execute a different key when pressed. In Visual Basic you can use the "KeyDown" event which occurs when a key is pressed in a particular control. This event is useful to detect the key pressed by the user. You can then change the function of the key pressed by sending a different keystroke to the active application using the "SendKeys.Send" method.

Skill level:
Moderate

Instructions

  1. 1

    Launch Microsoft Visual Basic Express, click "New Project" on the left pane of your computer screen, and double-click "Windows Forms Application" to create a new project.

  2. 2

    Double-click "RichTextBox" from the "Toolbox" pane to add it on your form. Double-click "Button" to create a new button on your form.

  3. 3

    Right-click the RichTextBox control and click "Properties". Click the event icon that resembles a lightning strike and double-click next to "KeyDown" to create a new procedure for this event.

  4. 4

    Copy and paste the following code inside the "KeyDown" event to execute a Return or Tab when the enter key is pressed:

    If e.KeyCode = Keys.Return Then

            If MessageBox.Show(Me, "Execute tab?", "Enter or Tab", MessageBoxButtons.YesNo) = vbYes Then
    
                SendKeys.Send("{TAB}")
    
    
    
            End If
    
        End If
    
  5. 5

    Press "F5" to run your program and type anything in the RichTextBox control then press enter to display a message box asking the user if they want to execute a return or a tab.

Don't Miss

Filter:
  • All types
  • Articles
  • Slideshows
  • Videos
Sort:
  • Most relevant
  • Most popular
  • Most recent

No articles available

No slideshows available

No videos available

By using the eHow.co.uk site, you consent to the use of cookies. For more information, please see our Cookie policy.