我希望暂停并在程序加载时显示我的启动画面。
我怎么能在vb.net winforms中做到这一点......
答案 0 :(得分:2)
好的,想象你的主窗体叫做Form1,你的昂贵/慢速初始化是在Load中完成的,你的初始屏幕形式叫做Splash。
您需要以下内容:
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
Dim StartTime = DateTime.Now
Dim Splash = New System.Threading.Thread(AddressOf SplashThread)
Splash.Start()
'Do lots of initialization - you wouldn't have this sleep in the real application
System.Threading.Thread.Sleep(10000)
Dim EndTime = DateTime.Now
Dim Diff = EndTime - StartTime
If Diff.TotalSeconds < 5 Then
'Splash hasn't been shown for very long - a little sleep is warranted.
System.Threading.Thread.Sleep(New TimeSpan(0, 0, 5) - Diff)
End If
SplashForm.Invoke(New Action(AddressOf SplashForm.Close))
Splash.Join()
End Sub
Private SplashForm As Splash
Private Sub SplashThread()
SplashForm = New Splash()
Application.Run(SplashForm)
End Sub
答案 1 :(得分:1)
快速而肮脏的解决方案:
Thread.Sleep
(请注意,在此期间不会进行任何UI更新,因此,如果您的用户点击某处,您的初始屏幕可能看起来很难看。)很好的解决方案:
用户友好型解决方案:
请注意,启动画面通常用于以下目的:当程序完成某些工作时,它们会吸引用户。如果你的程序不需要做初始工作,那么启动画面就很烦人,因为它浪费了用户的时间。