谁能给我一个进度条的例子?
想做个进度条,搞了半天学不会。
下面这个学习是我希望让进度条load30秒,这30秒内重复做一件事情,直到完成,则进度条结束。但是不行~谁教教我怎么搞?
private void MainForm_Shown(object sender, EventArgs e)
{
prgBar.Minimum = 1;
prgBar.Maximum = 30;
prgBar.Value = 1;
prgBar.Step = 1;
DateTime dtStart = DateTime.Now;
DateTime dtEnd = new DateTime(Convert.ToInt64(dtStart.Second + 30));
while (DateTime.Now != dtEnd)
{
prgBar.PerformStep();
}
}
------解决方案--------------------private void button4_Click(object sender, EventArgs e)
{
progressBar1.Minimum = 0;
progressBar1.Maximum = 30;
progressBar1.Step = 1;
for (int i = 0; i < 30; i++)
{
System.Threading.Thread.Sleep(1000);
progressBar1.PerformStep();
}
}
------解决方案--------------------private void Form1_Shown(object sender, EventArgs e)
{
prgBar.Minimum = 1;
prgBar.Maximum = 30;
prgBar.Value = 1;
prgBar.Step = 1;
DateTime dtEnd = DateTime.Now.AddSeconds(30);
while (DateTime.Now <= dtEnd)
{
TimeSpan vTimeSpan = new TimeSpan(dtEnd.Ticks - DateTime.Now.Ticks);
Application.DoEvents();
}
}