Solved

enter button hit runs button code

Posted on 2004-09-25
5
150 Views
Last Modified: 2010-04-23
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?
0
Comment
Question by:webwebwebweb
5 Comments
 
LVL 85

Expert Comment

by:Mike Tomlinson
ID: 12153548
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.
0
 

Author Comment

by:webwebwebweb
ID: 12153602
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
0
 
LVL 85

Accepted Solution

by:
Mike Tomlinson earned 215 total points
ID: 12153617
Set the KeyPreview Property of the form to True.  The code will look pretty much the same:

    Private Sub Form1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles MyBase.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

I see what you are saying about the accellerator keys now.  I don't think you can do that with the TabControl but I'm still looking...

~IM
0
 
LVL 4

Expert Comment

by:srcalc
ID: 12155427
You can always set

Form.AcceptButton = myButton
0
 
LVL 8

Expert Comment

by:wguerram
ID: 12175083
for the question how can you get _ in the title of tabpages?


There is no accelarator key for this control.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

735 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question