如何使用VB登录表单代码自动登录?

问题描述 投票:1回答:1

说用户名是ADMIN,密码是ADMIN。它应该是自动登录并且它没有显示FORM 3. Visual Basic的代码是什么。我的正确吗?

我的表单输出:

Login form

这是我的示例代码:

 Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    If TextBox1.Text <> "" And TextBox2.Text <> "" Then
        MsgBox("Invalid username and password, Please try again!", +vbExclamation, +vbOK)


    ElseIf TextBox1.Text = My.Settings.Username And
    TextBox2.Text = My.Settings.Password Then
        MsgBox("Login Successfuly! Good day.", +vbInformation, +vbOK)
        Form3.Show()
        Me.Hide()

    Else
        MessageBox.Show("Please complete the required fields.", "Authentication Error" + TextBox1.Text + TextBox2.Text, MessageBoxButtons.OK, MessageBoxIcon.Error)

    End If
End Sub
visual-studio login
1个回答
0
投票

下面的代码是简单的登录表单按钮点击事件代码。

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       If TextBox1.Text = "rfb" And TextBox2.Text = "reflection" Then
           Form2.Show()
       Else
           MsgBox("Sorry, username or password not found", MsgBoxStyle.OkOnly, "Invalid")
       End If
   End Sub

根据您的需要更改代码。

您可以在代码中更改用户名和密码,其中用户名为“rfb”,密码为“reflection”。 - 查看更多:http://www.visual-basic-tutorials.com/form/LoginT.htm#sthash.yb1ihiFB.dpuf

希望这会有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.