开发者

How to set Code execute only one time?.

开发者 https://www.devze.com 2023-03-23 23:49 出处:网络
In my Project I included a splash-screen. For that i wrote below code in Login Window Contractor. The Splash Screen is working perfectly. 开发者_StackOverflowBut after login, the main page is opened

In my Project I included a splash-screen.

For that i wrote below code in Login Window Contractor. The Splash Screen is working perfectly. 开发者_StackOverflowBut after login, the main page is opened. if it is closed, then login is opened.

In that the Splash Screen is cross the Login page. I don't want this.

How to do this: Splash Screen Shown only once in my project?

Help me...

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();
}


private void Form1_Load(object sender, EventArgs e)
{
    SplashScreen Splash = new SplashScreen();
    Splash.Show();
}

if you want the SplashScreen to close after 3 Seconds then use a timer in the SplashScreen and after 3 Seconds user this.close()


You can possibly pass a boolean parameter which will instruct the Login Constructor to display or not to display the Splash Screen.

 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();
    }


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();
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号