Search code examples
vb.netms-accessbutton

How to do the textbox keypress can click button automatically in vb.net


How to do the textbox keypress can click button automatically in vb.net.

Is there a solution so that after splitting in each textbox, the button login event can be done directly without being clicked?

Thanks

        Private uService As New Database.UserService()
  '''****Dapper*******
        Private Sub btnLogin_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnLogin.Click
            'add dapper logics here 
            Dim user = uService.GetUserByEmail(txtEmail.Text)

            If user Is Nothing Then
                MessageBox.Show("User does not exists")
                Return
            End If

            'confirm password
            If user.Password = txtPassword.Text Then
                MessageBox.Show("Successfull")
                'load your main window here
                Program.currentUser = user
                Me.ShowInTaskbar = False
                Me.Hide()
                Call (New FrmMain()).ShowDialog()
                Environment.Exit(0)
            Else
                MessageBox.Show("Invalid Login details")
            End If
        End Sub
        Private Sub txtEmail_KeyPress(sender As Object, e As KeyPressEventArgs) Handles txtEmail.KeyPress
   If e.KeyChar = Chr(13) Then
                parseBarcodeScan(txtEmail.Text)
            End If
        End Sub
 Private Sub parseBarcodeScan(input As String)
            Dim split = input.Split({"-", ":"}, StringSplitOptions.RemoveEmptyEntries).Select(Function(s) s.Trim())
            txtEmail.Text = split(1)
            txtPassword.Text = split(3)
        End Sub

Solution

  • You can just call the button's method:

      ...
      parseBarcodeScan(txtEmail.Text)
      btnLogin.PerformClick()
    End Sub