我需要在应用程序启动时显示闪屏界面几秒钟。有人知道如何实现吗?
非常感谢您的帮助。
我需要在应用程序启动时显示闪屏界面几秒钟。有人知道如何实现吗?
非常感谢您的帮助。
这是创建启动画面的最简单方法:
首先,在Form1.cs代码中的命名空间之前添加以下代码行:
using System.Threading;
现在,请按照以下步骤操作:
在你的应用程序中添加一个新表单
将这个新表单命名为FormSplashScreen
在BackgroundImage属性中,从你的文件夹中选择一张图片
添加一个progressBar
在Dock属性中,将其设置为Bottom
在MarksAnimationSpeed属性中,将其设置为50
在你的主表单中,默认情况下命名为Form1.cs,创建以下方法:
private void StartSplashScreen()
{
Application.Run(new Forms.FormSplashScreen());
}
在Form1.cs的构造方法中,添加以下代码:
public Form1()
{
Thread t = new Thread(new ThreadStart(StartSplashScreen));
t.Start();
Thread.Sleep(5000);
InitializeComponent();//此代码由Visual Studio自动生成
t.Abort();
}
现在,只需运行应用程序,它就会完美地工作。
试试这段代码
public partial class ssplashscreen : Form
{
public ssplashscreen()
{
InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
progressBar1.Increment(1);
if (progressBar1.Value == 100)
{
timer1.Stop();
this.Hide();
Form frm = new login();
frm.Show();
}
}
}
试试这个:
namespace SplashScreen
{
public partial class frmSplashScreen : Form
{
public frmSplashScreen()
{
InitializeComponent();
}
public int LeftTime { get; set; }
private void frmSplashScreen_Load(object sender, EventArgs e)
{
LeftTime = 20;
timer1.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
if (LeftTime > 0)
{
LeftTime--;
}
else
{
timer1.Stop();
new frmHomeScreen().Show();
this.Hide();
}
}
}
}