【问题标题】:How I can add a Splash Screen in C#?如何在 C# 中添加启动画面?
【发布时间】:2010-04-04 15:01:13
【问题描述】:

在 VB.NET 中,当您单击“添加新窗口”时,有一个添加启动画面的选项,但是当我使用 C# 执行此操作时,我找不到任何东西。

所以

如何在 C# 中添加启动画面?

【问题讨论】:

标签: c# visual-studio-2008


【解决方案1】:

(我现在在我的 Mac 上,所以我可能有点生疏......)

您需要打开您的项目首选项。

项目 -> 首选项

在第一个选项卡中,选择一个名为“启动对象”的下拉菜单。默认是 Form1.cs 你应该可以把它改成闪屏窗口。

【讨论】:

    【解决方案2】:

    在 Visual Studio 2010 中,这非常简单。只需将图像添加到您的解决方案,然后右键单击图像,并将其构建操作设置为“SplashScreen”。

    无需编码!

    【讨论】:

      【解决方案3】:

      添加对 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();
            }
         }  
      } 
      

      【讨论】:

      • @Alaxandre - 代码?! - 有一种方便的方法可以在没有代码的情况下做到这一点。但是,我确实喜欢能够务实地做事的想法,所以+1。
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-06-28
      • 2018-02-11
      • 1970-01-01
      • 2022-01-08
      • 1970-01-01
      相关资源
      最近更新 更多