进度条停在+ -90%

时间:2014-05-17 21:07:07

标签: c# user-interface progress-bar

我正在制作Q& A课程,你有15秒的时间来回答一个问题。问题是进度条只填充了90%并转移到下一个问题。我可以把代码放在这里,但我用荷兰语工作,所以也许很难理解。

    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();
        }
    }

以下是使用英文变量名称的相同代码:

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();
    }
}

1 个答案:

答案 0 :(得分:1)

看看这个:Disabling .NET progressbar animation when changing value?
因此,尝试将进度条增加2,然后减1.这应该可以解决动画问题

修改
另外,改变这一行

if (vraagFormulierProgressBar.Value < vraagFormulierProgressBar.Maximum)

到这个

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

编辑2
好的,这次我得到了它。首先,将进度条的最大值设置为300,将间隔设置为1(稍后可以修复时间)。接下来,用以下代码替换计时器滴答功能:

            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();
            }

对于使用英文名称感到抱歉,我将其从我的测试表单中删除了。无论如何,希望这有帮助!