0

ミリ秒数を取得してから進行状況バーを実行する関数を作成しましたが、その結果、進行状況バーの実行時間が定義よりも短くなります。

this.timerProgress.Tick += new System.EventHandler(this.timerProgress_Tick);

public void AnimateProgBar(int milliSeconds)
{
    if (!timerProgress.Enabled)
    {
        this.Invoke((MethodInvoker)delegate { pbStatus.Value = 0; });
        timerProgress.Interval = milliSeconds / 100;
        timerProgress.Enabled = true;
    }
}

private void timerProgress_Tick(object sender, EventArgs e)
{
    if (pbStatus.Value < 100)
    {
        pbStatus.Value += 1;
        pbStatus.Refresh();
    }
    else
    {
        timerProgress.Enabled = false;
    }
}
4

2 に答える 2

0

AnimateProgBar(100) を使用すると、最終的に 1 ミリ秒の間隔が作成されます。

timerProgress.Interval = ミリ秒; //100で割らない

this.timerProgress.Tick += new System.EventHandler(this.timerProgress_Tick);

public void AnimateProgBar(int milliSeconds)
{
    if (!timerProgress.Enabled)
    {
        this.Invoke((MethodInvoker)delegate { pbStatus.Value = 0; });
        timerProgress.Interval = milliSeconds; //do not divide by 100
        timerProgress.Enabled = true;
    }
}

private void timerProgress_Tick(object sender, EventArgs e)
{
    if (pbStatus.Value < 100)
    {
        pbStatus.Value += 1;
        pbStatus.Refresh();
    }
    else
    {
        timerProgress.Enabled = false;
    }
}
于 2013-01-29T03:55:53.840 に答える
0

を呼び出すとAnimateProgBar(1000)、次の計算が行われます: 1000 / 100. に等しい10

間隔はTimerすでにミリ秒単位です。したがって、効果的に間隔を に設定しています10ms

于 2013-01-29T03:57:35.923 に答える