启动画面 c#

Splash screen c#

我在 C# 方面不是很熟练,我做的是小项目,但现在我遇到了问题。我做了一个闪屏。一切正常。我制作了一个带有菜单的项目,在菜单中您可以选择不同的变体:加密、解密和退出。在每一个中,我都有一个 "home" 按钮。当我按下按钮时,在每个菜单中,每次都会出现启动画面,我需要等待。这很烦人。如何设置只工作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());
    }

还有一个问题。 Logo出现后,程序最小化。有什么建议吗?

如果您只想在程序启动时显示启动画面,请打开您的 Program.cs 并在 static class Program 部分添加一个计数器以计算表单运行。

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

您可以在第一次启动时设置一个运行时间标志,并在下次启动时带有时间戳,以表明您的应用已经运行ning,无需显示启动画面屏幕,它只是在不同的功能之间切换。

您还可以使用 Microsoft.VisualBasic.ApplicationServices 命名空间中的 WindowsFormsApplicationBase。它在 Winforms 项目中可用。此基础 class 提供了将启动画面添加到您的应用中的简便方法。