在ProgressBar控件中显示进度百分比

时间:2020-12-15 06:54:09

实现效果:

  在ProgressBar控件中显示进度百分比

知识运用:

  ProgressBar控件的Value属性    //控件的当前值

  Maximum属性      //ProgressBar正在使用的范围的上限

  PerformStep方法  //按照Step属性的数量增加任务栏的当前位置

  public void PerformStep()

实现代码:

        private void StartOrStop_Click(object sender, EventArgs e)
{
if (timer1.Enabled == false)
{
timer1.Enabled = true;
StartOrStop.Text = "停止";
}
else
{
timer1.Enabled = false;
StartOrStop.Text = "开始";
}
} private void timer1_Tick(object sender, EventArgs e)
{
if (progressBar1.Value == progressBar1.Maximum)
{
progressBar1.Value = progressBar1.Minimum;
}
else
{
progressBar1.PerformStep();
}
int process = 100 *
(progressBar1.Value - progressBar1.Minimum)
/ (progressBar1.Maximum - progressBar1.Minimum);
label1.Text = process.ToString()+"%" ;
}