我有两份表格。Form1 (下面有代码)和Splash (只是测试的默认表单)。
我的问题是,在应用程序运行之后,Splash不会隐藏。主窗体已加载,但Splash仍未关闭。
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的引用才能完成此任务。
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();
}
}
}提前谢谢你的帮助。
发布于 2010-07-15 07:57:17
啊,您正在使用Visual应用程序框架运行启动屏幕?尝尝这个。这是来自一个快速表单应用程序--请注意,我将所有名称和名称空间保留为默认值,因此您可能需要对代码进行更改。这个项目只有两种形式。Form2是飞溅屏幕。我在它上嵌入了一个背景图像,以确保它弹出正常,并且我可以将它与Form1区分开来。
我在我的项目中添加了对.NET Microsoft.VisualBasic的引用。
这是来自program.cs文件
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();
}
}
}我知道这和你用的不一样,但似乎很管用。
https://stackoverflow.com/questions/3253020
复制相似问题