在我的项目中,我添加了一个闪屏。
为此,我在Login Window Contractor中编写了以下代码。 Splash Screen工作正常。但登录后,主页面打开。如果关闭,则打开登录。
因为Splash Screen正在穿过Login页面。我不想要这个。
如何做到这一点:启动画面在我的项目中只显示一次?
帮助我......
public LogIn()
{
InitializeComponent();
Thread th = new Thread(new ThreadStart(Splash));
th.Start();
Thread.Sleep(3000);
th.Abort();
Thread.Sleep(1000);
}
private void Splash()
{
Welcome sp = new Welcome();
sp.ShowDialog();
}
答案 0 :(得分:5)
private void Form1_Load(object sender, EventArgs e)
{
SplashScreen Splash = new SplashScreen();
Splash.Show();
}
如果你希望SplashScreen在3秒后关闭,那么在SplashScreen中使用一个计时器,并在3秒后使用this.close()
答案 1 :(得分:2)
您可以传递一个布尔参数,该参数将指示登录构造函数显示或不显示启动画面。
public LogIn(boolean splashOpened)
{
InitializeComponent();
if(!splashOpened) //If Splash Screen is not opened , Open it
{
Thread th = new Thread(new ThreadStart(Splash));
th.Start();
Thread.Sleep(3000);
th.Abort();
Thread.Sleep(1000);
}
}
private void Splash()
{
Welcome sp = new Welcome();
sp.ShowDialog();
}
答案 2 :(得分:1)
private static Welcome sp;
public LogIn()
{
InitializeComponent();
if (sp == null)
{
Thread th = new Thread(new ThreadStart(Splash));
th.Start();
Thread.Sleep(3000);
th.Abort();
Thread.Sleep(1000);
}
}
private void Splash()
{
if (sp == null)
{
sp = new Welcome();
sp.ShowDialog();
}
}