Solved

detecting the enter keypress iin VB.net

Posted on 2006-11-15
7
13,947 Views
Last Modified: 2008-03-17
Hello

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
0
Comment
Question by:jbajaj
7 Comments
 
LVL 16

Expert Comment

by:Hillwaaa
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.

Cheers!
0
 
LVL 16

Expert Comment

by:Hillwaaa
ID: 17945612
Or in code, if you prefer:

Me.AcceptButton = Me.Button1
0
 

Author Comment

by:jbajaj
ID: 17945622
Cool

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
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 16

Expert Comment

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

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

0
 
LVL 5

Expert Comment

by:DEEPESH
ID: 17945654
Then in that case
if panel1.Visible = true then
   Me.AcceptButton = Me.Button1
Else
  Me.AcceptButton = Me.Button2
End if
0
 
LVL 5

Accepted Solution

by:
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


Regards,
Venkat
0
 
LVL 85

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
                Button1.PerformClick()
            Else
                Button2.PerformClick()
            End If
        End If
    End Sub
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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 …
Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

810 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