Winform Splash Screen - VB.NET - Timer

kal*_*lls 6 vb.net winforms

我在应用程序和该表单上有一个闪屏.我有一个计时器.

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

   SplashTimer.Start()

   ' Set application title
   ' Set Version
 Me.Show()
        'Me.Refresh()
        'System.Threading.Thread.Sleep(2000)
        'Login.ShowDialog()
        'Login.AllowTransparency = True
  End Sub
Run Code Online (Sandbox Code Playgroud)

定时器的间隔设置为5000.

  Private Sub SplashTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles SplashTimer.Tick
        SplashTimer.Stop()
        Login.Show()
        Login.AllowTransparency = True
        Me.Hide()
    End Sub
Run Code Online (Sandbox Code Playgroud)

我在这里设置了断点,但它似乎没有达到这个断点.我取消注释Me.Refresh()

启动画面正在关闭.然后使用继续按钮显示登录.单击"继续"按钮时

MainMenu.Show() 'this form should be shown as this is the main window of the application but it's not showing.
            Me.Close() 'closes login window
Run Code Online (Sandbox Code Playgroud)

没有窗口显示,应用程序挂起.任何输入将不胜感激.

Lar*_*ech 14

我建议使用Visual Studio提供的内置Splash Screen:

转到"Projects"菜单并选择"Add Windows Form"并选择Splash Screen模板:

在此输入图像描述

然后在Project的应用程序设置中,选择该表单作为Splash屏幕:

在此输入图像描述

您的启动表单应该是您的登录表单,而不是启动屏幕表单.

更新:

单击My Project的Application屏幕中最后一个图像上的"View Applications Events"按钮,并添加此代码以设置MinimumSplashScreenDisplayTime值:

Imports System.Collections.ObjectModel

Namespace My
  Partial Friend Class MyApplication
    Protected Overrides Function OnInitialize(commandLineArgs As ReadOnlyCollection(Of String)) As Boolean
      Me.MinimumSplashScreenDisplayTime = 5000
      Return MyBase.OnInitialize(commandLineArgs)
    End Function
  End Class
End Namespace
Run Code Online (Sandbox Code Playgroud)

您的启动画面将在屏幕上保留5000毫秒或5秒.