progressbar reaches maximum value but visually doesn't fill c#

Question:

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

The problem is that the progressbar hits the value of 100 , but visually on the splashscreen , it doesn't fill completely (which it should as it has reached its stipulated maximum value) and so ends up calling the next form to be fully loaded. I'll leave the splash code below, thanks!

Obs.: The commented places are from something else I 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();
    }

}

Answer:

Move the increment line to after the 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);
}
Scroll to Top