2017-03-18 62 views
0

說的用戶名是ADMIN,密碼是ADMIN。 它應該是自動登錄它不顯示FORM 3。代碼適用於Visual Basic。我的正確嗎?非常感謝你的幫助。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 
+0

你的第一個,如果條件是錯誤的。你想=不是<> – RoXX

回答

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

希望這將有助於

+0

在這部分我已經做得正確。但我的問題是它不會允許我登錄到另一種形式:( – Imcamshie

+0

你的意思是它不顯示「Form3」? –

+0

是表單3沒有顯示。 – Imcamshie