2016-09-06 23 views
2

我有一個應用程序與splashscreen。當啓動畫面消失時,窗口會在幾分之一秒內打開最大化,然後我的應用程序返回到背景(如最小化)。爲什麼會發生?我的表單已啓用WindowState = Maximized最大化窗口不顯示後閃屏

public Main() 
{ 
    //Splashscreen and new window 
    initializeWindow(); 
} 

public void SplashScreen() 
{ 
    Application.Run(new SplashScreen()); 
} 

private void initializeWindow() 
{ 
    //Start new Thread which shows Splash Screen 
    Thread t = new Thread(new ThreadStart(SplashScreen)); 
    t.Start(); 
    //Wait 3 seconds 
    Thread.Sleep(3000); 
    InitializeComponent(); 
    //Initialize form 
    t.Abort(); 
    //Abort and make main form the top form 
    //TopMost = true; <-- I commented this because it makes other applications not open unless if I minimize the window 
} 
+0

[正道(http://stackoverflow.com/a/15836105/1997232)的做閃屏。 [「左」的方式](http://stackoverflow.com/a/32469582/1997232)(你正在使用,因爲它似乎)。 – Sinatr

+0

[加載主窗體時顯示啓動畫面](http://stackoverflow.com/a/32421479/3110834) –

回答

2

暫停主線程是不是一個「健康」的解決方案,我會建議這樣做:

  1. 而不是打開主窗口打開閃屏的形式。
  2. 在啓動畫面窗體中設置一個關閉它的計時器。
  3. 在啓動畫面的FormClosed事件中打開主窗口。