启动画面不会隐藏 - 使用 Microsoft.VisualBasic 库 [英] Splash screen doesn't hide - using Microsoft.VisualBasic library

查看:21
本文介绍了启动画面不会隐藏 - 使用 Microsoft.VisualBasic 库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有 2 个表格.Form1(带有下面的代码)和 Splash(只是测试的默认表单).

I have 2 forms. Form1 (with code below) and Splash (just default form for test).

我的问题是在应用程序运行后,Splash 没有隐藏.主窗体已加载,但 Splash 仍未关闭.

My problem is that after application run the Splash doesn't hide. Main form is loaded but Splash is still not closed.

Form1 代码:

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;

namespace WindowsFormsApplication2
{
    class Program : WindowsFormsApplicationBase 
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            //Application.EnableVisualStyles();
            //Application.SetCompatibleTextRenderingDefault(false);
            //Application.Run(new Form1());

            // Show Form in Single-instance mode
            var prg = new Program();
            prg.EnableVisualStyles = true;
            prg.IsSingleInstance = true;
            prg.MinimumSplashScreenDisplayTime = 1000;
            prg.SplashScreen = new Splash();
            prg.MainForm = new Form1();
            prg.Run(args);
        }
    }
}

您必须添加对 Microsoft.VisualBasic 的引用才能执行此操作.

You must add reference to Microsoft.VisualBasic to work of this.

Splash 表单代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WindowsFormsApplication2
{
    public partial class Splash : Form
    {
        public Splash()
        {
            InitializeComponent();
        }
    }
}

预先感谢您的帮助.

推荐答案

啊,您正在使用 Visual Basic 应用程序框架来运行启动画面?尝试这个.这是来自快速表单应用程序 - 请注意,我已将所有名称和命名空间保留为默认值,因此您可能需要为您的代码更改此设置.该项目只有两种形式.Form2 是启动画面.我在它上面嵌入了一个背景图片,以确保它可以正常弹出并且我可以将它与 Form1 区分开来.

Ah you're using the Visual Basic Appplication Framework to run the splash screen? Try this. This is from a quick Forms application - note that I have left all names and namespace as default, so you may need to change this for your code. The project has two forms only. Form2 is the splash screen. I embedded a background image on it in order to ensure that it popped up okay and that I could differentiate it from Form1.

我在我的项目中添加了对 .NET Microsoft.VisualBasic 的引用.

I added a reference to .NET Microsoft.VisualBasic into my project.

这是来自 program.cs 文件

This is from the program.cs file

using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using Microsoft.VisualBasic.ApplicationServices;

namespace WindowsFormsApplication1
{
    static class Program
    {
        [STAThread]
        static void Main(string[] args)
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            new MyApp().Run(args);
        }
    }
    public class MyApp : WindowsFormsApplicationBase
    {
        protected override void OnCreateSplashScreen()
        {
            this.SplashScreen = new Form2();
        }
        protected override void OnCreateMainForm()
        {
            // Do your initialization here
            //...
            System.Threading.Thread.Sleep(5000);  // Test
            // Then create the main form, the splash screen will automatically close
            this.MainForm = new Form1();
        }
    }
}

我知道这与您使用的不同,但它似乎有效.

I know that is different to wht you're using but it seems to work.

这篇关于启动画面不会隐藏 - 使用 Microsoft.VisualBasic 库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆