2010-04-04 40 views
5

在VB.NET中,當你點擊添加新窗口時,有一個選項可以添加一個啓動畫面,但是當我用C#執行時,我找不到任何東西。如何在C#中添加啓動畫面?

so

如何在C#中添加啓動畫面?

回答

3

(我在我的Mac,所以我現在可能有點生疏...)

你需要打開你的項目的偏好。

項目 - >首選項

在第一個選項卡,選擇有所謂的「啓動對象」的下拉菜單。默認值是Form1.cs,你應該可以將其更改爲啓動畫面窗口。

2

添加對Microsoft.VisualBasic的引用。然後在Program.cs中編寫下面的代碼

static class Program 
{ 
    static void Main(string[] args) 
    { 
     Application.EnableVisualStyles(); 
     Application.SetCompatibleTextRenderingDefault(false); 
     new MyApp().Run(args); 
    } 

    public class MyApp : WindowsFormsApplicationBase 
    { 
     protected override void OnCreateSplashScreen() 
     { 
     this.SplashScreen = new MySplashScreen(); 
     } 

     protected override void OnCreateMainForm() 
     { 
     // Do stuff that requires time 
     System.Threading.Thread.Sleep(5000); 

     // Create the main form and the splash screen 
     // will automatically close at the end of the method 
     this.MainForm = new MyMainForm(); 
     } 
    } 
} 
+0

@Alaxandre - Code ?! - 沒有代碼就有一種方便的方法。不過,我確實喜歡能夠務實地做事情的想法,所以+1。 – Moshe 2010-04-04 15:21:09

+0

偉大的方式來添加一個,謝謝 – Saleh 2010-04-04 15:29:26

3

在Visual Studio 2010中,這非常簡單。只需將圖像添加到解決方案中,然後右鍵單擊該圖像,並將其構建操作設置爲「SplashScreen」。

無需編碼!

Setting a splash screen