private void button1_Click(object sender, EventArgs e) { //时间线程 timekeeper = new TimeKeeper(); Thread timeT = new Thread(new ThreadStart(timekeeper.runMethod)); timeT.Start(); //第一个进度条线程 myProgressBar1 = new MyProgressBar(1, timekeeper); myProgressBar1.setProgressBar += setProgress1Value; t1 = new Thread(new ThreadStart(myProgressBar1.runMethod)); t1.Start(); //第二个进度条线程 myProgressBar2 = new MyProgressBar(2, timekeeper); myProgressBar2.setProgressBar += setProgress2Value; t2 = new Thread(new ThreadStart(myProgressBar2.runMethod)); t2.Start(); //第三个进度条线程 myProgressBar3 = new MyProgressBar(3, timekeeper); myProgressBar3.setProgressBar += setProgress3Value; t3 = new Thread(new ThreadStart(myProgressBar3.runMethod)); t3.Start(); }
private void setProgress3Value(int value, int number) { if (this.progressBar3.InvokeRequired) { MyProgressBar m = new MyProgressBar(number); m.setProgressBar += setProgress3Value; this.Invoke(m.setProgressBar, new Object[] { value, number }); } else { if (value / (beishu * beishu) == 100) { this.button2_Click(new object(), new EventArgs()); } this.progressBar3.Value = value / (beishu * beishu); this.label6.Text = (value / (beishu * beishu)).ToString() + "%"; } }
private void setProgress2Value(int value, int number) { if (this.progressBar2.InvokeRequired) { MyProgressBar m = new MyProgressBar(number); m.setProgressBar += setProgress2Value; this.Invoke(m.setProgressBar, new Object[] { value, number }); } else { if ((value / beishu) > 0 && ((value / beishu) % 100) == 0) { this.progressBar2.Value = 100; this.label5.Text = "100%"; } else { this.progressBar2.Value = (value / beishu) % 100; this.label5.Text = ((value / beishu) % 100).ToString() + "%"; } } }