Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/271.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何使progressBar1在每次设置为timer interval的时间之前进行?_C#_.net_Winforms - Fatal编程技术网

C# 如何使progressBar1在每次设置为timer interval的时间之前进行?

C# 如何使progressBar1在每次设置为timer interval的时间之前进行?,c#,.net,winforms,C#,.net,Winforms,我有一个方法,我从计时器滴答声中调用它: private void NewsUpdate() { counter += 1; progressBar1.Value = counter * 10; progressBar1.Value = counter; label9.Text = counter.ToString(); label9.Visible = true; if (counter == 10) { clien

我有一个方法,我从计时器滴答声中调用它:

private void NewsUpdate()
{
    counter += 1;

    progressBar1.Value = counter * 10;
    progressBar1.Value = counter;

    label9.Text = counter.ToString();
    label9.Visible = true;

    if (counter == 10)
    {
        client.Encoding = System.Text.Encoding.GetEncoding(1255);
        page = client.DownloadString("http://rotter.net/scoopscache.html");
        TextExtractor.ExtractDateTime(page, newText, dateTime);

        StreamWriter w = new StreamWriter(@"d:\rotterhtml\rotterscoops.html");
        w.Write(page);
        w.Close();

        TextExtractor.ExtractText(@"d:\rotterhtml\rotterscoops.html", newText, dateTime);
        combindedString = string.Join(Environment.NewLine, newText);
        counter = 0;
    }
}
progressBar1
设置为0到100

我希望,如果我:

if (counter == 10)
然后,
progressBar1
将在10秒后移动到末尾

如果我将其设置为50,则为50秒,因此
progressBar1
应移动50秒,直到结束

设计器中的
计时器1
设置为1000ms

例如,现在的情况是:

counter += 1;

progressBar1.Value = counter * 10;
progressBar1.Value = counter;

label9.Text = counter.ToString();
label9.Visible = true;

if (counter == 10)
它将计数为10,
progressBar1
将移动10,然后返回到开头

我想知道,如果我将其更改为10 50或33,
progressBar1
将根据计数的秒数移动到结束

如果为33,则计数33,并在33秒后将
progressBar1
移动到末尾

我想做的是,如果我设置if==10,那么progressBar将增加10秒*10步,因此在10秒内progressBar将达到100。然后又一次(这个计时器是更新的,它应该一直运行,我不想停止它,我只需要检查10秒是否通过进行更新。我还希望progressBar将根据我在本例中设置的限制递增10,直到结束。如果它==10,则progressBar应每秒递增10。例如,如果我将它设置为==50)然后,progressBar应每s递增2,如果您想要一个具有n步的计数器,其中n是完成的秒数

有两种方法可以实现这一点:

  • (首选)设置
    ProgressBar
    Maximum
    属性。这将使一切自动进行

    counter++;
    progressBar1.Maximum = 33; //This could be set in the designer, or on init
    progressBar1.Value = counter;
    
  • 自己计算时间间隔。将计数器除以总秒数,然后乘以范围(本例中为100)


  • 根据您的评论,您所有的其他代码听起来都不错。

    您想和谁做
    progressBar1.Value=counter*10;progressBar1.Value=counter;
    ?@user3739928感谢您的澄清,希望我的新答案能有所帮助!您可能希望将该评论加入到您的问题中,以供将来的读者阅读。
    counter++;
    progressBar1.Value = (int)Math.Round((counter / 33f) * 100);