u010684460 2013-08-22 01:43 采纳率: 0%
浏览 1459

C#中闪屏问题如何解决

如何在c#中,建一个闪屛窗体,程序启动时,闪屏显示一段时间,自动关闭后,打开的是主窗体

  • 写回答

1条回答 默认 最新

  • ChatGPTᴼᴾᴱᴺᴬᴵ 2023-01-13 15:59
    关注

    可以使用以下方法在 C# 中创建闪屏窗体:

    • 创建一个新窗体,命名为 "SplashScreen"。
    • 在窗体的 Load 事件中设置定时器,指定闪屏窗体显示的时间。
    • 在定时器的 Tick 事件中关闭闪屏窗体,并打开主窗体。

    示例代码如下:

    public partial class SplashScreen : Form
    {
        private Timer timer = new Timer();
    
        public SplashScreen()
        {
            InitializeComponent();
    
            timer.Interval = 5000; // 5 秒
            timer.Tick += Timer_Tick;
            timer.Start();
        }
    
        private void Timer_Tick(object sender, EventArgs e)
        {
            timer.Stop();
            this.Close();
            MainForm mainForm = new MainForm();
            mainForm.Show();
        }
    }
    

    在主程序中只需要 new 一个 SplashScreen 窗口就可以了,具体代码如下

    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new SplashScreen());
    }
    

    在这里我们设置了窗体在5s后关闭,并且打开了MainForm窗体,可以根据需要调整时间。

    评论

报告相同问题?

悬赏问题

  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度
  • ¥15 c# 使用NPOI快速将datatable数据导入excel中指定sheet,要求快速高效
  • ¥15 再不同版本的系统上,TCP传输速度不一致
  • ¥15 高德地图2.0 版本点聚合中Marker的位置无法实时更新,如何解决呢?
  • ¥15 DIFY API Endpoint 问题。
  • ¥20 sub地址DHCP问题