progressbar reaches maximum value but visually does not fill c#

Asked

Viewed 351 times

3

I am working with a software in C#, in which after a login screen, appears a splashscreen with a progressbar that when it reaches its maximum value (100), she calls the main form of the program.

The problem is that the progressbar reaches the value of 100, but visually in splashscreen, It is not completely filled (which it should because it has reached its stipulated maximum value) and then ends up calling the next form in being fully loaded. I’m gonna drop the code splash, thank you!

Note: The commented sites are of another thing that was testing so they are not relevant in the case.

private void EfectTime()
{
    //SplashTimer.Interval = 100;
    SplashTimer.Tick += new EventHandler(SplashTimer_Tick);
    SplashTimer.Enabled = true;
    //this.Opacity = 1;
}

//  private bool Efect = true;

private void SplashTimer_Tick(object sender, EventArgs e)
{   
    pgrBar.Increment(1);

    //if (Efect) 
    //{
    //    this.Opacity -= 0.01D;
    //}

    if (pgrBar.Value == 100)
    {
        //Efect = false;

        SplashTimer.Enabled = false;
        FrmTelaPrincipal frmTelaprincipal = new FrmTelaPrincipal();
        frmTelaprincipal.Show();
        this.Hide();
    }

}
  • How far does it go? This is not due to the fact that the main screen opens as soon as progress reaches 100?

  • yes really, it doesn’t complete because the next form opens. But isn’t its upload synchronized with its value? I think it would be supposed that when it reached 100 it would be fully filled and immediately call the form.

  • Maybe she is, she just doesn’t have time to see =)

2 answers

2

Move the increment line to after condition.

private void SplashTimer_Tick(object sender, EventArgs e)
{    
    //if (Efect) 
    //{
    //    this.Opacity -= 0.01D;
    //}

    if (pgrBar.Value == 100)
    {
        //Efect = false;

        SplashTimer.Enabled = false;
        FrmTelaPrincipal frmTelaprincipal = new FrmTelaPrincipal();
        frmTelaprincipal.Show();
        this.Hide();
    }

    pgrBar.Increment(1);
}
  • Unfortunately it did not work, and still opened the form twice.

  • I created a test program and I just checked again and that’s all it took. When moving the increment line, it cannot stay within the condition, but below. Check the value of the Maximum property (to 100) and the Step (to 1) of the progression.

0

I don’t know if it’s the best way, but I figured it out:

public Form1()
        {
            InitializeComponent();
        }
        public int prog = 0;        

private void tempo_Tick(object sender, EventArgs e)
        {
            if (prog != 105)
            //if(pbIni.Value <= pbIni.Maximum)
            {
                pbIni.Increment(1);
                prog++;
            }
            else
            {
                Thread.Sleep(2000);//Esta linha apenas se quiser mais esperar um tempinho a mais
                Application.Exit();
            }

        }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.