我创建了一个获得毫秒数的函数,然后运行进度条,但结果是进度条的运行时间少于定义的时间 .
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;
}
}
2 回答
使用AnimateProgBar(100),最终将创建1毫秒的Interval .
对
AnimateProgBar(1000)
的调用将导致以下计算:1000 / 100
. 这等于10
.Timer
间隔已经是毫秒 . 所以你有效地将间隔设置为10ms
.