2012-04-30 61 views
1

Windows窗體VB應用程序..我添加了splashScreen到我的應用程序。它閃爍只有一秒鐘然後消失,所以我添加了一個睡眠計時器到我的表單加載事件...現在的問題是splashScreen保持打開,即使在應用程序退出後,而不是簡單地在sleeptimer結束時關閉..導致此窗體的Load事件的部分如下:即使在應用程序退出後仍然保持打開屏幕

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Me.Load 

Threading.Thread.Sleep(5000) 
Me.WindowState = FormWindowState.Maximized 
Dim _year As String = System.DateTime.Now.Year.ToString 

我使用的是通過將MYPROJECT創建一個股票閃屏。它的代碼如下: 公共NotInheritable類SplashScreen1

'TODO: This form can easily be set as the splash screen for the application by going to the "Application" tab 
' of the Project Designer ("Properties" under the "Project" menu). 


Private Sub SplashScreen1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load 


    'Set up the dialog text at runtime according to the application's assembly information. 

    'TODO: Customize the application's assembly information in the "Application" pane of the project 
    ' properties dialog (under the "Project" menu). 

    'Application title 
    If My.Application.Info.Title <> "" Then 

    Else 
     'If the application title is missing, use the application name, without the extension 
     'ApplicationTitle.Text = System.IO.Path.GetFileNameWithoutExtension(My.Application.Info.AssemblyName) 
    End If 

    'Format the version information using the text set into the Version control at design time as the 
    ' formatting string. This allows for effective localization if desired. 
    ' Build and revision information could be included by using the following code and changing the 
    ' Version control's designtime text to "Version {0}.{1:00}.{2}.{3}" or something similar. See 
    ' String.Format() in Help for more information. 
    ' 
    ' Version.Text = System.String.Format(Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor, My.Application.Info.Version.Build, My.Application.Info.Version.Revision) 

    Version.Text = System.String.Format(Version.Text, My.Application.Info.Version.Major, My.Application.Info.Version.Minor) 

    'Copyright info 
    Copyright.Text = My.Application.Info.Copyright 


End Sub 

末級

沒有什麼更多的與此相關的功能在所有..其餘部分用來填充表單標籤和textboxes ...如果我刪除了Threading.Thread.Sleep(5000)這一行,初始屏幕只會閃爍一秒,但在完成後退出。任何想法?

+0

無影響u能告訴我其中U調用閃屏的代碼。從哪裏創建啓動畫面的對象並使其可見。 – kbvishnu

+0

查看輸出窗口,您是否看到「第一次機會異常」通知? –

+0

輸出中沒有第一次機會異常通知.. – Skindeep2366

回答

4

答案是不使用Thread.Sleep但設置MinimumSplashScreenDisplayTime

要設置該(時間的最小長度,以毫秒爲單位被顯示在初始屏幕):

  1. 選擇Project>[Your project name] Properties
  2. Application標籤
  3. View Application Events按鈕,點擊旁邊的SP睫毛屏幕下拉
  4. 選擇從對象選擇的MyApplication對象下拉(左上菜單)
  5. 選擇從方法OnCreateSplashScreen方法的聲明下拉(右上菜單)
  6. 添加follwing線在OnCreateSplashScreen方法MinimumSplashScreenDisplayTime = 10000

(如果您還沒有這樣做的話,你需要設置你的閃屏形式進行應用程序的啓動畫面,看到how to specify the splashscreen

+0

還有更多的,該屬性已設置爲2秒。 –

+0

@HansPassant - 是2秒是默認的,這就是爲什麼我認爲OP沒有爲項目指定啓動畫面 –

+0

我實際上確實通過「myproject」指定了啓動畫面......如果我進入該splashscreen視圖並右鍵單擊,選擇屬性那裏沒有財產那裏有任何類型的時間值.. – Skindeep2366

1
FormName.MinimumSplashScreenDisplayTime = 10000 

它會顯示閃屏10秒。

1

感謝很多關於一個幫助......這是現在的工作。但我不得不註釋掉

Me.WindowState = FormWindowState.Maximized 

出於某種原因,它打破了最小飛濺時間..

+0

有時候,我的初始形式有一個例外,這導致(我不知道爲什麼)使啓動畫面保持打開狀態。 –

+0

@AnonymousPi在try/catch塊中拋出初始屏幕代碼,並打破異常。 – Skindeep2366

+0

當然,你可以嘗試去除異常,特別是如果你不需要它。 –

0

這發生在我身上,它是由OnLoad事件形式的錯誤引起的。我清除了錯誤,啓動畫面開始正常運行。

順便說一句,我有這樣的形式設置爲最大化,即設置有開機畫面

相關問題