VB.NET:多种形式的问题

时间:2011-09-15 22:06:07

标签: vb.net forms

大家好!我在VB.NET中有一个问题。在为登录屏幕创建和测试我的GUI以显示工资单系统的主页时,存在这个问题。

启动画面正常加载,并显示登录表单。我输入用户名和密码(例如用户名:Admin,密码:12345),登录成功。问题出现了:当主菜单出现时,登录屏幕出现AGAIN,此时此屏幕应该已经关闭。使用“显示”,“隐藏”和“关闭”是否有任何问题?

这是我的三种形式的代码。

一个。启动画面

Public Class frmSplashScreen

Private Sub tmrSplashScreen_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tmrSplashScreen.Tick
    Me.Hide()
    frmLogin.Focus()
    frmLogin.Show()
End Sub

End Class

B中。登录表单(用于系统访问)

Public Class frmLogin

Public userName As String
Public passWord As String

Private Sub cmdExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdExit.Click

    End

End Sub

Private Sub cmdSubmit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cmdSubmit.Click

    userName = txtUsername.Text
    passWord = txtPassword.Text

    If userName = "Admin" And passWord = "12345" Then
        MsgBox("Access Granted! Welcome to BYTE!", MsgBoxStyle.Information, "Byte EGC Payroll System")
        Me.Close()
        frmMainMenu.Show()
        frmMainMenu.Focus()
    Else
        MsgBox("Access Denied!", MsgBoxStyle.Critical, "Byte EGC Payroll System")
    End If

End Sub

结束班

最后:

℃。主菜单。

Public Class frmMainMenu

Private Sub ExitToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ExitToolStripMenuItem.Click

    End

End Sub

Private Sub frmMainMenu_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

    Me.WindowState = FormWindowState.Maximized

End Sub

Private Sub AboutToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles AboutToolStripMenuItem.Click

    MsgBox("Byte" & vbCrLf & "By: JU-CHAN", vbInformation, "Byte Payroll System")

End Sub

结束班

非常感谢帮助。谢谢! :)

3 个答案:

答案 0 :(得分:2)

我打赌你的问题是你的启动画面中的计时器仍在触发_tick事件并再次启动登录页面。

也许在隐藏启动画面之前添加tmrSplashScreen.Stop()

或者更好。完全摆脱闪屏,它们是邪恶的。

答案 1 :(得分:2)

计时器保持滴答声,导致启动画面重新加载,然后隐藏,再次显示登录屏幕。

尝试将其放入tmrSplashScreen刻度处理程序:

tmrSplashScreen.Enabled = False

答案 2 :(得分:1)

登录表单显示时,您的启动画面不应控制。只有在程序启动时才应该使用启动画面,因为它在后台进行大量处理之后才能实际启动程序。只是为了做到这一点而显示一个启动画面会让最终用户感到烦恼。

由于您上面的基本登录屏幕看起来不会占用大量资源,因此更好的选择是使用以下流程:

  

显示登录屏幕
  如果密码成功则为
   - 显示闪屏
   - 在后台加载应用程序
   - 加载应用程序后,显示主窗口并隐藏splash sprfeen

一些示例代码是:

Module modMain
    'In a module 
    Public frmSpl As frmSplash
    Public frmMain As frmMainMenu

    Public Sub Main(ByVal args() as String)
        dim frmLogin as New frmLogin

        'Assume frmLogin is a modal form
        frmLogin.Show

        'A public property set on the Login form
        If frmLogin.Passed = True Then Do
            'Load and display the splash screen
            frmSpl = New frmSplash
            frmSpl.Cursor = Cursors.WaitCursor
            frmSpl.Show()
            Application.DoEvents()

            'If there is any code needed to run before displaying the Main Form
            'do it here 

            frmMain = New frmMainMenu

            'Begin running standard application loop for frmMainMenu
            Application.Run(frmMain)
        End If
    End Sub
End Module

然后在frmMainMenu中你会得到类似的代码:

Public Class frmMainMenu

    Private Sub frmMainMenu_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

        Try
            Me.Cursor = Cursors.WaitCursor
            Me.SuspendLayout

            Me.WindowState = FormWindowState.Maximized

            'Put any other loading code needed for this form here
        Catch (ex as Exception)
            'Handle exceptions here
        Finally
            'Hide the splash screen
            frmSpl.Hide()
            frmSpl.Dispose()

            'Display the form
            Me.ResumeLayout
            Me.Cursor = Cursors.Default
            Me.Show
        End Try

    End Sub