[英]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.