主窗体:包含一个label和一个timer
Splash窗体: 包含一个label和一个progressbar。窗体的TopMost属性为True,确保Splash窗体显示在主窗体上面,同时由于无法准确获知主窗体载入数据的时间,所以设置progressbar 的Style属性为Marquee
Splash窗体: 包含一个label和一个progressbar。窗体的TopMost属性为True,确保Splash窗体显示在主窗体上面,同时由于无法准确获知主窗体载入数据的时间,所以设置progressbar 的Style属性为Marquee
Public MainFormState As Integer主窗体代码:
Public Class Form1 Private Sub Form1_Load(sender As Object,e As EventArgs) Handles MyBase.Load MainFormState = 0 Dim frm2 As New Form2 frm2.Show()
Timer1.Start() End Sub
Private Sub Timer1_Tick(sender As Object,e As EventArgs) Handles Timer1.Tick Timer1.Stop() Label1.Text = "启动中……"
Console.WriteLine("状态:" & MainFormState)
Threading.Thread.Sleep(1000) Dim sum As Integer = 0 For i As Integer = 0 To 1000000 sum += 1 Application.DoEvents() Next MainFormState = 1 Label1.Text = "正在导入数据" Console.WriteLine("状态:" & MainFormState)
For i As Integer = 0 To 1000000 sum += 1 Application.DoEvents() Next
MainFormState = 2 Label1.Text = "启动完成" Console.WriteLine("状态:" & MainFormState) End Sub End Class
Splash窗体代码:
Public Class Form2 Private Sub Form2_Load(sender As Object,e As EventArgs) Handles MyBase.Load Me.CheckForIllegalCrossThreadCalls = False Dim thrCheckState As New Threading.Thread(AddressOf checkstate) thrCheckState.Start() End Sub Sub checkstate() Dim blLoaded As Boolean = False Do While (blLoaded = False) Select Case MainFormState Case 0 Label1.Text = "启动中……" blLoaded = False Case 1 Label1.Text = "正在导入数据" blLoaded = False Case Else Label1.Text = "启动完成" blLoaded = True End Select Loop Me.Close() End Sub End Class
由于.net平台下C#和vb.NET很相似,本文也可以为C#爱好者提供参考。
学习更多vb.net知识,请参看vb.net 教程 目录