2010-04-04 42 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