Henry Gathigira Henry Gathigira - 6 months ago 13
Vb.net Question

How to Set Enter is ok on Textbox in vb.net

I have a password textbox (Tbx1) and a Login button (Btn1). What code will i put where so that when the user
inputs password and presses enter, Btn1 clickevents will be exucuted?

Answer

on Form Misc Properties set the accept button to be Btn1. Equally, you can set a cancel button too to be executed whenever the user presses Esc button.

Code version (through the constructor):

Public Sub New()

    ' This call is required by the designer.
    InitializeComponent()

    ' Add any initialization after the InitializeComponent() call.
    Me.AcceptButton = Btn1
End Sub