1

I need to show Splash screen and login form at same time when run my application.

static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        SplashImageForm f = new SplashImageForm();
        f.Show();

        Application.Run(f);
        Application.Run(new Form1());
    }
V.V
  • 875
  • 3
  • 25
  • 54

2 Answers2

2

Try this:

Login Form:

    public partial class LoginForm : Form
{


    private void buttonLogin_Click(object sender, EventArgs e)
    {
        //check username password
        if(texboxUser == "user" && texboxPassword == "password")
        {
            DialogResult = DialogResult.OK;
            Close();
        }
        else
        {
            MessageBox.Show("Wrong user pass");
        }
    }
}

In Splash form:

private void Splash_Shown(object sender, EventArgs e)
    {
        LoginForm loginF = new LoginForm();

        loginF.ShowDialog();

        if (loginF.DialogResult == DialogResult.OK)
        {
            loginF.Close();
        }
    }

In Program.cs:

static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Splash());

    }
user4340666
  • 1,453
  • 15
  • 36
1

Show your splashscreen from within your form1 and also set the splashscreens its parent to the form1. Because I assume this need to be closed after a certain amount of time. This will also cover the fact that if you close your form1, the splashscreen will also close because of the parent-child relationship.

private void Form1_Load(object sender, EventArgs e)
{
    var f = new SplashImageForm ();
    f.Show( this );
}
Sievajet
  • 3,443
  • 2
  • 18
  • 22