设计过程:
ProcessBar窗体:
在窗体中央放一个progressBar1控件与label1,label2
声明访问类型改为public:
(即)
public System.Windows.Forms.ProgressBar progressBar1;
public System.Windows.Forms.Label label1;
public System.Windows.Forms.Label label2;
Form1窗体:
放置按钮button1
private void button1_Click(object sender, EventArgs e)
{
ProcessBar pj = new ProcessBar();
pj.Show();
//开始处理工作
for (int i = 0; i < 200000; i++)
{
if (i % 2000 == 0)
{
if (pj.progressBar1.Value == 100)
pj.progressBar1.Value = 0;
pj.progressBar1.Value++;
pj.label1.Text = "已完成:" + string.Format("{0:p}", (double)pj.progressBar1.Value / 100);
pj.label2.Text = "正在处理:第" + i + "程序";
Application.DoEvents();
}
}
pj.Close();
}