private void picSure_Click(object sender, EventArgs e)
{
this.progressBar1.Visible = true;//显示进度条
Thread th = new Thread(new ThreadStart(Exec));
th.Start();
}
void Exec()
{
try
{ DateTime dt1 = DateTime.Now;//操作开始,开始计时
.......//(一系列操作)
DateTime dt2 = DateTime.Now;//操作结束,计时结束
TimeSpan ts = dt2 - dt1;//操作过程用去的时间,用于设置progressBar1的最大值
}
catch (Exception ex)
{
.......
}
}
我想在点击做个进度条,上面是我自己的思路。。那个高手能告诉我progressBar1.Value怎么赋值,怎么更新?
{
this.progressBar1.Visible = true;//显示进度条
Thread th = new Thread(new ThreadStart(Exec));
th.Start();
}
void Exec()
{
try
{ DateTime dt1 = DateTime.Now;//操作开始,开始计时
.......//(一系列操作)
DateTime dt2 = DateTime.Now;//操作结束,计时结束
TimeSpan ts = dt2 - dt1;//操作过程用去的时间,用于设置progressBar1的最大值
}
catch (Exception ex)
{
.......
}
}
我想在点击做个进度条,上面是我自己的思路。。那个高手能告诉我progressBar1.Value怎么赋值,怎么更新?
.......//(一系列操作)
DateTime dt2 = DateTime.Now;//操作结束,计时结束
TimeSpan ts = dt2 - dt1;//操作过程用去的时间,用于设置progressBar1的最大值
/////////////////////////////////
设置ProgressBar的最大值应该在开始的时候设置的,你可以把这个最大值设置为一系列操作的步骤数(当然这是不准确的)
然后每执行完一个操作,步进就加1,到目前为止,进度条的准确性都是相对的,没有绝对的准确
要的步骤吧,用Backgroudworker
MainManager patManager = new Manager();
patManager.onReportProgress = new DoReportProgress(OnReportProgress); // 同步更新进程条
patManager.DisposeRecord(); // 执行数据处理 private void OnReportProgress(int current, string strInfor)
{
if (this.InvokeRequired)
{
this.Invoke(new DoReportProgress(OnReportProgress), new object[] { current % 100, strInfor });
}
else
{
this.tsprogressMain.Maximum = 100;
this.tsprogressMain.Value = (int)current % 100;
this.tsprogressInfor.Text = strInfor;
this.statusMain.Refresh();
}
} // MainManager类
namespace PatrolManage
{
public delegate void DoReportProgress(int current, string strInfor);
public class MainManager
{
public DoReportProgress onReportProgress;
public void DisposeRecord()
{
for (int i=0; i<100; i++)
{
onReportProgress(i, "正在处理数据...");
// do something
}
}
}
}