Link to home
Start Free TrialLog in
Avatar of webwebwebweb
webwebwebweb

asked on

enter button hit runs button code

I have a textbox and a button, Once the user types in this textbox and then clicks enter, the code for the button should run,how is this done?


Also how can you get _ in the title of tabpages?
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

First question:

    Private Sub txtInput_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles txtInput.KeyPress
        If e.KeyChar = ControlChars.Cr Then ' if enter was pressed
            e.Handled = True ' get rid of annoying beep
            Button1_Click(Nothing, Nothing) ' run Button1_Click code
        End If
    End Sub

Second question:

    Select your TabControl.
    In the TabPages property, click on the three dots "..."
    Select the TabPage you want to modify.
    Find the Text property on the right side of the dialog.
    Edit it, adding your underscore where you want it.
    Press OK.
Avatar of webwebwebweb
webwebwebweb

ASKER

sorry i mean not for a particular text box but for the form.
if im doing anything on the form and press enter i want the button ones code to be run. sorry dude

the second answer wont work, usually on menus or wateva i wud go F&ile to bring it up with the underline so the user can then use alt and wateva letter
ASKER CERTIFIED SOLUTION
Avatar of Mike Tomlinson
Mike Tomlinson
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
You can always set

Form.AcceptButton = myButton
for the question how can you get _ in the title of tabpages?


There is no accelarator key for this control.