Solved

enter button hit runs button code

Posted on 2004-09-25
5
147 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
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
You can always set

Form.AcceptButton = myButton
0
 
LVL 8

Expert Comment

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


There is no accelarator key for this control.
0

Featured Post

What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Object to array 7 27
Limiting string to two deciamls 18 30
Copy/Clone an object. 9 10
Recommendation vb6 to vb.net or others 14 25
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 …
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video discusses moving either the default database or any database to a new volume.
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

744 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now