繁体   English   中英

启动画面C#

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

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