Maybe you want something like this:
public void AnimateProgBar (int milliSeconds)
{
if (!timer1.Enabled) {
progressBar1.Value = 0;
timer1.Interval = milliSeconds / 100;
timer1.Enabled = true;
}
}
private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value < 100) {
progressBar1.Value += 1;
progressBar1.Refresh();
} else {
timer1.Enabled = false;
}
}
Then you just have to call AnimateProgBar(2000)
to have your ProgressBar
animated during 2 seconds.
EDIT: Sorry, I posted code in VB.NET. Modified to C#.
EDIT: You can add the handler and call the function in this way (for example):
private void Form1_Load(object sender, EventArgs e)
{
this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
AnimateProgBar(2000);
}
5
solved Using ProgressBar for specific time [closed]