Solved

enter button hit runs button code

Posted on 2004-09-25
5
152 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 86

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 86

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: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

705 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