detecting the enter keypress iin

Posted on 2006-11-15
Last Modified: 2008-03-17

I have a login screen containing a panel having two textboxes login and password and a login button

Now when a user enters the username and a passsword, and presses enter , he should automatically login, no need to use tab to go to the button , or use the mouse

How do I detect the "Enter" keypress and then automatically have the login button activated ?

Please help asap
Question by:jbajaj
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
LVL 16

Expert Comment

ID: 17945603
Hi jbajaj,

For the form you are in, there is an AcceptButton property.  Set this in the properties window to the name of the Login button and you're done.

LVL 16

Expert Comment

ID: 17945612
Or in code, if you prefer:

Me.AcceptButton = Me.Button1

Author Comment

ID: 17945622

I have two panels and each having two seperate buttons .
Only one of them is visible at a time

When one is visible I want it to have the accrpt button and vice versa

How do I do that

Is using a variable between them the only solution
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

LVL 16

Expert Comment

ID: 17945649
When you make the panel1 visible, make button1 the acceptbutton,

Then when panel2 is made visible, make button2 the acceptbutton.


Expert Comment

ID: 17945654
Then in that case
if panel1.Visible = true then
   Me.AcceptButton = Me.Button1
  Me.AcceptButton = Me.Button2
End if

Accepted Solution

Venkateswarlu Kaipu earned 500 total points
ID: 17946029
   Public Function KeyAscii(ByVal UserKeyArgument As KeyPressEventArgs) As Short
        KeyAscii = Asc(UserKeyArgument.KeyChar)
    End Function

    Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
        If KeyAscii(e) = 13 Then
            MsgBox("you press ENTER key")
        End If
    End Sub

LVL 86

Expert Comment

by:Mike Tomlinson
ID: 17947808
Or you can do something like...

    Protected Overrides Function ProcessCmdKey(ByRef msg As System.Windows.Forms.Message, ByVal keyData As System.Windows.Forms.Keys) As Boolean
        If keyData = Keys.Enter Then
            If Panel1.Visible Then
            End If
        End If
    End Sub

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

It’s quite interesting for me as I worked with Excel using for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
In this video, viewers will be given step by step instructions on adjusting mouse, pointer and cursor visibility in Microsoft Windows 10. The video seeks to educate those who are struggling with the new Windows 10 Graphical User Interface. Change Cu…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

688 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