Password Enter

Hi all

I have made a vb.net form to log users in that it has 2x labels 2x boxes (user name and password) 2x button (logon and cancel).

How to have a commend come of the the enter button when press in the password boxes.

Eg. you type in your user name and then password and press enter... so you login.

At the moment the user has to click logon.

Matt
Matb396Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

x77Commented:
You need a cathc KeyPress event on Password TextBox.
when e.KeyChar = ControlChars.Cr then do the same action as Logon Button.

    Private Sub TxtPwd_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TxtPwd.KeyPress
       If e.KeyChar = ControlChars.Cr Then
          e.Handled = True
         .....
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Avinash DesaiSr Software EngineerCommented:
Hi

Write a code under the password textbox KeyDown event  and catch the key code using e.keychar , validate and invoke the login button click

Regards
Avinash Desai
0
Matb396Author Commented:
Thanks
0
Mike TomlinsonHigh School Computer Science, Computer Applications, and Mathematics TeachersCommented:
Another approach is to set the AcceptButton() Property of the FORM to your login button.  This will cause it to be clicked when the user hits enter.  In the button click event you can check to see if one the fields is still empty and cause focus to return there.  If both fields are filled in then go ahead and attempt the login...
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Me.AcceptButton = Me.btnLogon
    End Sub

    Private Sub btnLogon_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogon.Click
        If tbUserName.Text.Trim.Length = 0 Then
            tbUserName.Focus()
        ElseIf tbPassword.Text.Trim.Length = 0 Then
            tbPassword.Focus()
        Else
            ' ... normal button login code here ...
            MessageBox.Show("Logon")
        End If
    End Sub

End Class

Open in new window

0
TommySzalapskiCommented:
If you are using Visual Studio, you just set the Default property of the Logon button to true and it is clicked on Enter.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.