且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

启动画面不会隐藏 - 使用 Microsoft.VisualBasic 库

更新时间:2023-01-26 12:56:59

啊,您正在使用 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.