我有一个VB.NET应用程序,表现奇怪(或者可能并不奇怪,我只是缺少一些东西)。VB.NET应用程序触发关闭窗体关闭事件
我有一个登录表单,当用户单击确定并成功登录时,它会加载主应用程序表单。
但是,当我显示主窗体并关闭登录窗体时,应用程序正在触发关闭事件。
这是因为应用程序认为登录窗体是唯一窗体打开,从而触发关闭事件?
下面是登录例程的代码,当我最后调用Me.Close()时是关闭事件被触发时。我是不是在做坏事?我曾经在VB6中这样做过,没有任何问题(我知道它们有很大的不同)。
请注意,它不是frmMain,无论我尝试打开哪种形式,都会发生这种情况。
谢谢。
Private Sub btnOK_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnOK.Click
'iLoginResult = 0 : Success
' 1 : Invalid user name or password
' 2 : Other login error
' 3 : User not authorized
Dim iLoginResult As Integer = 2
Dim sTopLabel As String = ""
Dim sBottomLabel As String = ""
Me.Cursor = Cursors.WaitCursor
Try
If Me.txtUserName.Text.ToString.Trim = "" Or Me.txtPassword.Text.ToString.Trim = "" Then
MessageBox.Show("Enter a user name and password before continuing.", "DocGen", MessageBoxButtons.OK, MessageBoxIcon.Warning)
Exit Try
End If
iLoginResult = modGeneral.bLogin(Me.txtUserName.Text.ToString.Trim, Me.txtPassword.Text.ToString.Trim)
Select Case iLoginResult
Case 1 : sTopLabel = "The user name or password is incorrect" : sBottomLabel = "Check your user name then type your password again."
Case 2 : sTopLabel = "General login error" : sBottomLabel = "Contact your information technology department."
Case 3 : sTopLabel = "Unauthorized access" : sBottomLabel = "Contact your information technology department to gain access to this system."
End Select
If iLoginResult > 0 Then
RaiseDialog(sTopLabel, sBottomLabel)
Me.txtPassword.Text = ""
Me.txtUserName.Focus()
Me.txtUserName.SelectAll()
End If
Catch ex As Exception
RaiseError("", "frmLogin.btnOK_Click", Err.Number, Err.Description)
End Try
Me.Cursor = Cursors.Default
If iLoginResult = 0 Then
If Me.cmbEnvironment.Text = "Development" Then modGeneral.gbIsProduction = False
frmMain.Show()
Me.Close()
End If
End Sub
或者调用Me.Hide()而不是Me.Close() – asawyer 2010-09-10 17:53:44
因此,无论您指定解决方案的启动形式是什么将用于触发关闭事件?我在应用程序启动事件中有初始化的东西,你说的是移动到其他地方并做类似Sub Main的事情?对不起,VB.NET是一种新的东西。 – Tom 2010-09-10 17:54:22
@Tom,是的,再次检查我的编辑 – msarchet 2010-09-10 18:02:35