Winform 启动画面 - VB.NET - 计时器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8993685/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Winform Splash Screen - VB.NET - Timer
提问by kalls
I have a splash screen on the application and on that form. I have a timer.
我在应用程序和该表单上有一个闪屏。我有一个计时器。
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
Interval on the timer is set to 5000.
定时器的间隔设置为 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
I set breakpoint here but it doesn't seem to hit this breakpoint. I uncommented Me.Refresh()
我在这里设置了断点,但它似乎没有达到这个断点。我取消注释 Me.Refresh()
Splash screen is closing. Then Login is shown with a continue button. When you click continue button
启动画面正在关闭。然后登录显示一个继续按钮。当您单击继续按钮时
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
No window shows up and the application is hanging. Any inputs will be greatly appreciated.
没有窗口出现,应用程序挂起。任何输入将不胜感激。
回答by LarsTech
I would suggest using the built in Splash Screen that is provided by Visual Studio:
我建议使用 Visual Studio 提供的内置启动画面:
Go to the "Projects" menu and select "Add Windows Form" and select the Splash Screen template:
转到“项目”菜单并选择“添加 Windows 窗体”并选择启动画面模板:
Then in the Project's Application settings, select that form to be the Splash screen:
然后在项目的应用程序设置中,选择该表单作为启动画面:
Your start up form should be your login form, not the splash screen form.
您的启动表单应该是您的登录表单,而不是初始屏幕表单。
Update:
更新:
Click on the "View Application Events" button on the last image from your My Project's Application screen and add this code to set the MinimumSplashScreenDisplayTimevalue:
单击“我的项目”的“应用程序”屏幕中最后一个图像上的“查看应用程序事件”按钮,并添加以下代码以设置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
Your splash screen will remain on the screen for 5000 milliseconds, or 5 seconds.
您的启动画面将在屏幕上停留 5000 毫秒或 5 秒。
回答by Mark Hall
Try adding a Module to your program with a Public Sub Main
Method. Set your project Startup options to Sub Main. You can then do something like:
尝试使用方法将模块添加到您的程序中Public Sub Main
。将您的项目启动选项设置为 Sub Main。然后,您可以执行以下操作:
Module Module1
Dim frmSplash As SplashScreen1
Dim frmLogin As Login
Dim frmMain As MainMenu
Dim splashTimer As Timer
Public Sub Main()
splashTimer = New Timer()
AddHandler splashTimer.Tick, AddressOf TimerTick
splashTimer.Interval = 5000
splashTimer.Start()
frmSplash = New SplashScreen1
frmSplash.ShowDialog()
frmLogin = New Login
Dim result As DialogResult = frmLogin.ShowDialog
If result <> DialogResult.OK Then
End
End If
frmMain = New MainMenu
frmMain.ShowDialog()
End Sub
Private Sub TimerTick(sender As Object, e As EventArgs)
splashTimer.Stop()
frmSplash.Close()
End Sub
End Module
Project Settings:
项目设置:
回答by user2238156
What I found is that timer events aren't fired until the Load event/method is completed. I put a thread.sleep in the activated event/method and it gives me the desired result. So I'm trying to show a splash screen with a couple different background images and this works fine.
我发现在 Load 事件/方法完成之前不会触发计时器事件。我在激活的事件/方法中放置了一个 thread.sleep,它给了我想要的结果。所以我试图显示一个带有几个不同背景图像的启动画面,这很好用。
回答by Momen TCG
I Found A sample Solution (My SplashScreen Named "Loading" and My Start Form Named "login")
我找到了一个示例解决方案(我的 SplashScreen 名为“ Loading”,我的起始表单名为“ login”)
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
If Timer1.Interval = 5000 Then
Me.Hide()
Login.Show()
End If
End Sub