首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Splash不隐藏-使用Microsoft.VisualBasic库

Splash不隐藏-使用Microsoft.VisualBasic库
EN

Stack Overflow用户
提问于 2010-07-15 06:32:21
回答 1查看 698关注 0票数 2

我有两份表格。Form1 (下面有代码)和Splash (只是测试的默认表单)。

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

Form1代码:

代码语言:javascript
复制
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的引用才能完成此任务。

Splash表单代码:

代码语言:javascript
复制
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();
        }
    }
}

提前谢谢你的帮助。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2010-07-15 07:57:17

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

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

这是来自program.cs文件

代码语言:javascript
复制
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();
        }
    }
}

我知道这和你用的不一样,但似乎很管用。

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/3253020

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档