繁体   English   中英

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

[英]How I can add a Splash Screen in C#?

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

所以

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

这是一个很好的例子。 如果您使用的是Windows窗体。

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

无需编码!

设置启动画面

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

您需要打开项目首选项。

项目 - >偏好

在第一个选项卡中,选择一个名为“Startup Object”的下拉菜单。 默认值为Form1.cs您应该能够将其更改为初始屏幕窗口。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM