[英]Splash screen c#
我在c#方面不那么先進,我做一些小項目,但是現在我遇到了問題。 我做了一個啟動畫面。 一切正常。 我用菜單創建一個項目,然后在菜單中可以選擇不同的變體:加密,解密和退出。 在每個窗口中,我都有一個“主頁”按鈕。 當我按下按鈕時,在每個菜單中,每次都會出現該初始屏幕,我需要等待。 它很煩人。 如何設置僅工作1次(僅在啟動程序時)?
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Soft.Properties;
using System.Threading;
namespace Soft
{
public partial class Meniu : Form
{
public Meniu()
{
Thread t = new Thread(new ThreadStart(SplashStart));
t.Start();
Thread.Sleep(5000);
InitializeComponent();
t.Abort();
}
public void SplashStart()
{
Application.Run(new LOGO());
}
還有一個問題。 出現徽標后,程序將最小化。 有什么建議嗎?
如果只想在啟動程序時顯示啟動屏幕,請打開Program.cs並在靜態類“程序”部分中添加一個計數器,以運行計數表單。
public static int counter = 0;
然后像這樣編輯代碼:
public Meniu()
{
InitializeComponent();
Program.counter++;
if (Program.counter == 1) // If first run minimize and show splash screen
{
this.WindowState = FormWindowState.Minimized;
Thread t = new Thread(new ThreadStart(SplashStart));
t.Start();
Thread.Sleep(5000);
t.Abort();
}
else // If not first run
{
this.WindowState = FormWindowState.Normal;
}
}
public void SplashStart()
{
Application.Run(new LOGO());
}
您可以在首次啟動時設置運行時標志,並為下次啟動設置時間戳,以表明您的應用程序已在運行,無需顯示啟動屏幕,只需在不同功能之間切換即可。
您還可以使用Microsoft.VisualBasic.ApplicationServices
命名空間中的WindowsFormsApplicationBase
。 在Winforms項目中可用。 此基礎類提供了將初始屏幕添加到您的應用程序的簡便方法。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.