Call form after loading screen

3

I have already checked some answers that have been made about closing a form after logging in and so on. I tested the many methods in my function, but I did not succeed.

Soon my problem is not a login but a progressbar screen.

I'm doing the following: I have a form that displays a "loading" (progressBar) screen that after loading the entire bar, it should close that form and call a second form containing data.

The problem is that, I can not close the loading form (it is the program's initialization form). If you know any method ...

//primeiro form
public Form1()
{
   InitializeComponent();
}
private void timer1_Tick(object sender, EventArgs e)
{
   if (progressBar1.Value < 100)
   {
      progressBar1.Value = progressBar1.Value +2;
   }
   else if (progressBar1.Value == 100)
   {
      timer1.Enabled = false;
      Form2 f2 = new Form2();
      f2.Show(); // aqui chamo o segundo form
      //this.Close() // tentei essa função para fechar o Form1, mas sem sucesso também
   }
}
    
asked by anonymous 10.05.2017 / 23:18

3 answers

2

Simple, just do this:

private void timer1_Tick(object sender, EventArgs e)
{
   if (progressBar1.Value < 100)
   {
      progressBar1.Value = progressBar1.Value +2;
   }
   else if (progressBar1.Value == 100)
   {
      timer1.Enabled = false;
      Hide();
      Form2 f2 = new Form2();
      f2.Show(); // aqui chamo o segundo form
   }
}
    
11.05.2017 / 01:43
2

In your main project, in the case of the project that is set to initialize your application, in the Program.cs class write the code as it will work.

static class Program
{
    /// <summary>
    /// The main entry point for the application.
    /// </summary>
    [STAThread]
    static void Main()
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);

        FrmLogin frmLogin = new FrmLogin();

        if (frmLogin.ShowDialog() == DialogResult.OK)
            Application.Run(new FrmPrincipal());
    }
}

In this case I treat the screen as a dialog box and according to the return of the login screen button I open the main screen.

Create this other method and call it inside the constructor

    private void InitializeTimer()
    {
        // Call this procedure when the application starts.
        // Set to 1 second.
        timer1.Interval = 1000;
        timer1.Tick += new EventHandler(timer1_Tick);

        // Enable timer.
        timer1.Enabled = true;
    }

It looks like this:

     public Form1()
     {
         InitializeComponent();

         InitializeTimer();
     }

And this method that you had created leave this way:

    private void timer1_Tick(object sender, EventArgs e)
    {
        if (progressBar1.Value < 100)
        {
            progressBar1.Value = progressBar1.Value + 10;
        }
        else if (progressBar1.Value == 100 && timer1.Enabled)
        {
            timer1.Enabled = false;
            this.DialogResult = DialogResult.OK;
        }
    }

I tested it and it worked out.

    
10.05.2017 / 23:25
0

I do not quite understand your doubt. But you want to start another form first rather than login, what is the beginning of your program? If that is the doubt, just change it link

    
10.05.2017 / 23:31