2012-01-24 48 views
7

我在應用程序和窗體上有一個啓動畫面。我有一個計時器。Winform啓動畫面 - VB.NET - 定時器

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 

間隔計時器設置爲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 

我在這裏設置斷點,但它似乎並沒有打這個斷點。我取消註釋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 

無窗顯示出來,並且應用程序掛。 任何輸入將不勝感激。

+0

是否有理由避免內置的SplashScreen窗體? – LarsTech

+0

這是應用程序的當前狀態。我可以建議使用內置的模板。 – kalls

+0

@LarsTech - 它是內置的模板。 – kalls

回答

13

我建議使用內置的是由Visual Studio提供的閃屏:

轉到「項目」菜單,選擇「添加Windows窗體」,然後選擇閃屏模板:

enter image description here

然後在該項目的應用程序設置中,選擇的形式是閃屏:

enter image description here

你的啓動形式應該是你的登錄表單,而不是閃屏形式。

更新:

從我的項目的應用程序屏幕中的最後圖像上單擊「查看應用程序事件」按鈕,添加以下代碼來設置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 

你飛濺屏幕將保持在屏幕上5000毫秒或5秒。

+0

它是內置模板。 – kalls

+0

@ kalls我用一個例子更新了答案,爲啓動畫面添加了延遲。不需要定時器。 – LarsTech

3

嘗試使用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 

項目設置:

+0

我還沒有試過這個霍爾先生。以前的方法爲我工作。我很感謝你的回答。 – kalls

0

我發現那是什麼計時器事件不會被觸發,直到Load事件/方法完成。 我把一個thread.sleep放在激活的事件/方法中,它給了我想要的結果。 所以我試圖顯示一個閃屏與幾個不同的背景圖像,這工作正常。