Solved

enter button hit runs button code

Posted on 2004-09-25
5
151 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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

This tutorial demonstrates one way to create an application that runs without any Forms but still has a GUI presence via an Icon in the System Tray. The magic lies in Inheriting from the ApplicationContext Class and passing that to Application.Ru…
I think the Typed DataTable and Typed DataSet are very good options when working with data, but I don't like auto-generated code. First, I create an Abstract Class for my DataTables Common Code.  This class Inherits from DataTable. Also, it can …
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial

732 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