【问题标题】:Splash screen c#启动画面 c#
【发布时间】:2017-02-12 16:24:18
【问题描述】:

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

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

【问题讨论】:

  • 这很愚蠢。当您必须隐藏您的 UI 启动缓慢的事实时,您只需要一个启动屏幕。您唯一需要隐藏的是您在代码中放置了一个 Thread.Sleep() 调用,它完全休眠了太长时间。删除该声明。现在删除启动画面,因为您不再需要它了。如果您希望用户知道您是谁,请添加帮助 + 关于对话框。

标签: c# screen splash-screen


【解决方案1】:

如果您只想在程序启动时显示启动画面,请打开您的 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());
        }

【讨论】:

    【解决方案2】:

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

    【讨论】:

      【解决方案3】:

      您还可以使用来自Microsoft.VisualBasic.ApplicationServices 命名空间的WindowsFormsApplicationBase。它在 Winforms 项目中可用。这个基类提供了将启动画面添加到您的应用程序的简单方法。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2013-04-06
        • 1970-01-01
        • 2021-12-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多