简体   繁体   中英

How I can add a Splash Screen in C#?

In VB.NET there is an option to add a Splash Screen when you click Add New Window but when I do that with C#, I can't find any thing.

so

How I can add a Splash Screen in C#?

Here is a nice example. If you are using windows forms.

In Visual Studio 2010, this is really easy. Simply add an image to your Solution, then right-click on the image, and set it's Build Action to "SplashScreen".

No coding required!

设置启动画面

(I'm on my Mac now so I may be a bit rusty...)

You need to open up your project preferences.

Project -> Preferences

In the first tab, select there is a dropdown menu called "Startup Object". The default is Form1.csYou should be able to change that to a splash screen window.

Add a reference to Microsoft.VisualBasic. Then write the following code in 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();
      }
   }  
} 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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