进度条在+-90%处停止

本文关键字:+-90% | 更新日期: 2023-09-27 18:04:04

我在做一个问答节目,你有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();
    }
}

进度条在+-90%处停止

看看这个:在改变值时禁用。net进度条动画?
因此,尝试将进度条增加2,然后减少1。这应该可以解决动画问题

编辑
同时,修改

if (vraagFormulierProgressBar.Value < vraagFormulierProgressBar.Maximum)

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

编辑2
好的,这次我明白了。首先,将进度条的最大值设置为300,间隔设置为1(稍后可以修改时间)。接下来,用下面的代码替换timer tick函数:

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

很抱歉用了英文名,这是我从考试表格上抄下来的。无论如何,希望这对你有帮助!