2008-12-25 42 views
1

我有一個應用程序。啓動畫面的問題 - C# - VS2005

首先我顯示啓動畫面,一種形式,這飛濺稱之爲另一種形式。

問題:當顯示飛濺形式,如果我再打開就撲通頂部其他應用程序,然後最小化這個新打開的應用程序窗口,啓動畫面變成白色。我如何避免這種情況?我希望我的飛濺清晰顯示,不受任何應用程序的影響。

回答

5

你需要在不同的線程來顯示啓動畫面 - 目前新的形式加載代碼擋住了閃屏的UI線程。

啓動一個新的線程,該線程創建閃屏和呼叫Application.Run(splash)。這將在該線程上啓動一個新的消息泵。然後,您需要在啓動屏幕的UI線程(例如,使用Control.Invoke/BeginInvoke)準備好後,將其主線程調用回線程,以便啓動屏幕可以自行關閉。

重要的是要確保你不要試圖修改從錯誤的線程UI控件 - 僅使用控制上創建的一個。

+1

不幸的是,這對初學者來說相當複雜。我確定有一些圖書館或者這樣做了嗎? – configurator 2008-12-25 13:49:33

+0

我不知道框架中的任何內容。可能會有第三方庫讓它更容易。 – 2008-12-25 18:53:58

1

我有一個類似的問題,你可能想看看。 Stack Overflow answer我得到了完美的工作 - 你可能想看看。

3

NET框架有閃屏優異的內置支持。啓動一個新的WF項目,Project + Add Reference,選擇Microsoft.VisualBasic。添加一個新表單,將其命名爲frmSplash。打開Project.cs並使其看起來像這樣:

using System; 
using System.Windows.Forms; 
using Microsoft.VisualBasic.ApplicationServices; 

namespace WindowsFormsApplication1 { 
    static class Program { 
    [STAThread] 
    static void Main(string[] args) { 
     Application.EnableVisualStyles(); 
     Application.SetCompatibleTextRenderingDefault(false); 
     new MyApp().Run(args); 
    } 
    } 
    class MyApp : WindowsFormsApplicationBase { 
    protected override void OnCreateSplashScreen() { 
     this.SplashScreen = new frmSplash(); 
    } 
    protected override void OnCreateMainForm() { 
     // Do your time consuming stuff here... 
     //... 
     System.Threading.Thread.Sleep(3000); 
     // Then create the main form, the splash screen will close automatically 
     this.MainForm = new Form1(); 
    } 
    } 
}