110,502
社区成员
发帖
与我相关
我的任务
分享
private void button1_Click(object sender, EventArgs e)
{
ProgressBar pb = new ProgressBar();
this.Controls.Add(pb);
pb.BringToFront();
pb.Minimum = 1;
pb.Maximum = 2;
pb.Value =1;
//pb.Style = ProgressBarStyle.Blocks;
pb.Style = ProgressBarStyle.Continuous;
//pb.Style = ProgressBarStyle.Marquee;
pb.Visible = true;
Application.DoEvents();
pb.Value = 2;
//pb.PerformStep();
//pb.Increment(1);
pb.Update();
pb.PerformLayout();
pb.Refresh();
//第一段
Application.DoEvents();
System.Threading.Thread.Sleep(1000);
//第二段
Application.DoEvents();
System.Threading.Thread.Sleep(1000);
pb.Visible = false;
}
private void button2_Click(object sender, EventArgs e)
{
ProgressBar pb = new ProgressBar();
this.Controls.Add(pb);
pb.BringToFront();
pb.Minimum = 0;
pb.Maximum = 20;
pb.Value = 0;
Task.Factory.StartNew(new Action(() =>
{
do
{
pb.Invoke(new MethodInvoker(() => pb.Value++));
Thread.Sleep(200);
} while (pb.Value < pb.Maximum);
pb.Invoke(new MethodInvoker(() => pb.Visible = false));
}));
}