Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Throw event when enter key pressed (textbox)? 3

Status
Not open for further replies.

CraigBest

Programmer
Aug 1, 2001
545
US
Hi Folks

Quick question: I have a login window where the user types in a user name and password, and nost of the users are used to hitting the return key on finishing typing the password and having the form execute as though the OK button was pressed.

I looked in Help and found that the Return key is not handled by the keyup event on a textbox, but that there is a way of overriding this behavior. Of course there is no example. Can someone explain to me how I can set things up so a return key press (KeyUp or similar) will trigger a procedure or the click event of a button?

Thanks!




CraigHartz
 
Use the ProcessDialogKey Method

Code:
    Protected Overrides Function ProcessDialogKey(ByVal keyData As System.Windows.Forms.Keys) As Boolean
        Try
            If keyData = Keys.Enter Then
                Return MessageBox.Show("I hit the enter key so do some stuff!")
            Else
                Return MessageBox.Show(MyBase.ProcessDialogKey(keyData))
            End If
        Catch Excep As System.Exception

        End Try
    End Function

____________ signature below ______________
You are a amateur developer until you realize all your code sucks.
Jeff Atwood

 
Thanks, that does work -- but it also has the unfortunate side effect of nullifying the effect of the Tab key. Any was I kan keep the tab key working and also have this functionality?

CraigHartz


CraigHartz
 
Select the form and in the properties go to the Accept Button and set it to the button you want. When the enter is pressed this button is clicked.
 
Perfect, just like the old default button in 6. Works great, thanks.




CraigHartz
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top