ProgressBar 基础应用(简单)

创建一个简单的窗体,界面如下:

image

 

“基础应用”按钮对应的代码:


/// 方法一: /// 修改 progressBar1.Value 来使进度条显示发生变化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEasy_Click(object sender, EventArgs e) { progressBar1.Minimum = 1; progressBar1.Maximum = 100000; for (int i = 0; i < progressBar1.Maximum; i++) { progressBar1.Value = i; } } /// <summary> /// 方法二: /// 设置 Step 属性,调用 PerformStep() 来使进度条显示发生变化 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnEasy_Click1(object sender, EventArgs e) { progressBar1.Minimum = 1; progressBar1.Maximum = 100000; progressBar1.Step = 1; for (int i = 0; i < progressBar1.Maximum; i++) { progressBar1.PerformStep(); } }

 

各分钟按钮对应代码:


/// <summary> /// 分钟按钮的 Tag 值里分别保存了 2, 5, 10 /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnAnySecond_Click(object sender, EventArgs e) { progressBar1.Minimum = 0; progressBar1.Maximum = 100; progressBar1.Value = 0; progressBar1.Step = 1; Button btn = sender as Button; timer1.Interval = Convert.ToInt32(btn.Tag) * 10; count = 0; timer1.Enabled = true; } private int count = 0; private void timer1_Tick(object sender, EventArgs e) { progressBar1.PerformStep(); if (++count == 100) { timer1.Enabled = false; } } private void btnStop_Click(object sender, EventArgs e) { progressBar1.Value = 0; timer1.Enabled = false; }

 

posted on 2011-11-29 15:02  SkySoot  阅读(586)  评论(0编辑  收藏  举报

导航