Printable Version of Topic

Click here to view this topic in its original format

Dream.In.Code _ VB.NET _ ENTER KEY

Posted by: mary21clare 2 Jul, 2009 - 10:34 AM

I have a login form that I made. The user enters a username in textbox1 and then enters a password in textbox2. The user then hits the submit button (button2) and from there it works beautifully. The problem is, I would also like the user to be able to hit the "enter" key after they fill out the password textbox (textbox2) and have it be like they pressed the submit button. When the user hits enter right now, the form hides... I don't know what to do! please help!

Posted by: zippp 2 Jul, 2009 - 10:52 AM

use the keypress event

CODE

Private Sub textbox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textbox2.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then

'here you put your code...the code from the submit button and the code for hidding textbox1 or textbox2

End If
End Sub


i hope this will help you

Posted by: mary21clare 2 Jul, 2009 - 11:30 AM

QUOTE(zippp @ 2 Jul, 2009 - 10:52 AM) *

use the keypress event

CODE

Private Sub textbox2_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles textbox2.KeyPress
If Asc(e.KeyChar) = Keys.Enter Then

'here you put your code...the code from the submit button and the code for hidding textbox1 or textbox2

End If
End Sub


i hope this will help you



I guess what I don't understand is what code you put in there. How can i link it to button1 being clicked?

Posted by: PsychoCoder 2 Jul, 2009 - 01:38 PM

A much easier way (required no code) is to set the Form's http://msdn.microsoft.com/en-us/library/system.windows.forms.form.acceptbutton.aspx to your submit button (If this is a Windows Application)

Posted by: zippp 2 Jul, 2009 - 09:31 PM

you put there the submit button's code and when you hit enter the action will be the same like button2.

actualy you have to choice. you type in the user and pass and u click the submit button or just hit the enter key.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)