使用VB验证用户身份后关闭登录表单的问题

时间:2011-09-22 22:41:52

标签: vb.net forms authentication

我创建了一个非常通用的登录表单,允​​许用户访问应用程序。我的问题是在加载申请表后让登录表单关闭。我已经在代码的注释中描述了细节。任何帮助将不胜感激。

Public Class frmUserLogin
Inherits System.Windows.Forms.Form

Private pass As String
Private username As String
Private attempt As Integer = 0
Private Admin As String
Private Password As String

Private Sub btnLogin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLogin.Click

    username = "Admin"
    pass = "Password"

    If (txtUsername.Text = username) And (txtPassword.Text = pass) Then
        MsgBox("That is correct")
        frmApplicationWindow.Show()

        'I am trying to close the login form after the user is able to load the frmapplicationwindow

        'frmUserLogin.close() , when I use this it says I can use it because it is referring to the same instance of itself
        'me.close , when I use this it closes both the user login form and the application form

    Else
        MsgBox("wrong username or pass, try again")
        attempt += 1
    End If

    If attempt = 3 Then
        MsgBox("You have reached the allowed number of login attempts")
        Me.Close()
    End If
End Sub

结束班

1 个答案:

答案 0 :(得分:1)

只需使用Me.Hide代替Me.Close。