一个古老的问题—如何在WinForm中显示Splash Screen

步骤1:
在SplashScreen窗体上拖放一个Timer控件,并设置Interval属性为3000(代表停留3秒钟),在时间到后关闭窗体;

    Private Sub Timer1_Elapsed(ByVal sender As System.ObjectByVal e As System.Timers.ElapsedEventArgs) Handles Timer1.Elapsed
        
Me.Close()
    
End Sub

步骤2:
在主窗体的构造函数中使用下列代码:
Public Sub New()
        
MyBase.New()

        
Me.Cursor = Cursors.AppStarting
        
'该调用是 Windows 窗体设计器所必需的。
        InitializeComponent()

        
'在 InitializeComponent() 调用之后添加任何初始化

        
'加载图书类型至TreeView
        PopulateBookType()

        
'显示Splash Screen
        Dim frm As New SplashForm
        frm.FormBorderStyle 
= FormBorderStyle.None
        frm.MaximizeBox 
= False
        frm.MinimizeBox 
= False
        frm.StartPosition 
= FormStartPosition.CenterScreen
        frm.ControlBox 
= False
        frm.ShowInTaskbar 
= False
        frm.ShowDialog()

        
Me.StartPosition = FormStartPosition.CenterScreen
        
Me.Cursor = Cursors.Default
    
End Sub
注意在上述代码中需要使用frm.ShowDialog()而不能使用frm.Show,否则将不能显示SplashScreen;另外frm.ShowInTaskbar=false将使得在显示SplashScreen同时,不会在任务栏中显示内容。
参考网址:
Windows Forms FAQ - Windows Forms
Windows Forms FAQ - Windows Forms 2.0
posted on 2005-05-07 21:17  enjoy .net  阅读(560)  评论(0编辑  收藏  举报