Gurpreet.S
Gurpreet.S

Reputation: 89

Progressbar stops at +-90%

I am making a Q&A program where you have 15 sec to answer a question. The problem is that the progress bar is only filling like 90% and moves to the next question. I can put the code here but I have worked in Dutch so maybe it's difficult to understand.

    private void volgendeVraagFormButton_Click(object sender, EventArgs e)
    {
        //button for going to next question
        vraagFormulierProgressBar.Value = 0;
        vraagFormulierTimer.Start();
    }

    private void vraagFormulierTimer_Tick(object sender, EventArgs e)
    {
        if (vraagFormulierProgressBar.Value < vraagFormulierProgressBar.Maximum)
            vraagFormulierProgressBar.PerformStep();
            //checks if the value is lower than 15 sec(max)
        else
        {      //stops the progress if the 15 secs are over and moves to next question
            vraagFormulierTimer.Stop();
            vraagFormulierProgressBar.Value = 0;
            vraagFormulierTimer.Start();
        }
    }

Here's the same code with variable names in English:

private void nextQuestionFormButton_Click(object sender, EventArgs e)
{
    //button for going to next question
    questionFormProgressBar.Value = 0;
    questionFormTimer.Start();
}

private void questionFormTimer_Tick(object sender, EventArgs e)
{
    if (questionFormProgressBar.Value <questionFormProgressBar.Maximum)
       questionFormProgressBar.PerformStep();
        //checks if the value is lower than 15 sec(max)
    else
    {      //stops the progress if the 15 secs are over and moves to next question
       questionFormTimer.Stop();
       questionFormProgressBar.Value = 0;
       questionFormTimer.Start();
    }
}

Upvotes: 0

Views: 844

Answers (1)

Blue0500
Blue0500

Reputation: 725

Take a look at this: Disabling .NET progressbar animation when changing value?
So try to increment your progress bar by 2, then decrement by 1. That should fix the animation problem

Edit
Also, change this line

if (vraagFormulierProgressBar.Value < vraagFormulierProgressBar.Maximum)

to this

if (vraagFormulierProgressBar.Value + 1 < vraagFormulierProgressBar.Maximum)

Edit 2
OK, I've got it this time. First, set the maximum of your progress bar to 300 and the interval to 1 (You can fix the timing later). Next, replace the timer tick function with this:

            if (progressBar1.Value < progressBar1.Maximum - 1)
            {
                progressBar1.Increment(2);
                progressBar1.Increment(-1);
            }
            else
            {
                timer1.Stop();

                progressBar1.Maximum = 10000;
                progressBar1.Value = 10000;
                progressBar1.Value = 9999;
                progressBar1.Value = 10000;
                System.Threading.Thread.Sleep(150);

                progressBar1.Value = 0;
                progressBar1.Maximum = 300;
                timer1.Start();
            }

Sorry about using the English names, I copied this out of my test form. Anyway, hope this helps!

Upvotes: 1

Related Questions