用C# 实现进度条
using System;using System.Collections.Generic;using System.ComponentModel;using System.Data;using System.Drawing;using System.Linq;using System.Text;using System.Windows.Forms;using System.Threading;namespace VerticalProgressBar{ public partial class Form1 : Form { protected BackgroundWorker worker = null; public Form1() { InitializeComponent(); worker = new BackgroundWorker(); worker.WorkerReportsProgress = true; worker.DoWork = new DoWorkEventHandler(worker_DoWork); worker.ProgressChanged = new ProgressChangedEventHandler(worker_ProgressChanged); worker.RunWorkerCompleted = new RunWorkerCompletedEventHandler(worker_RunWorkerCompleted); worker.RunWorkerAsync(); } void worker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e) { MessageBox.Show("Complete!"); } void worker_ProgressChanged(object sender, ProgressChangedEventArgs e) { //this.progressBar1.Value = e.ProgressPercentage; this.progressBar2.Value = e.ProgressPercentage; } void worker_DoWork(object sender, DoWorkEventArgs e) { int count = 100; for (int i = 0; i <= count; i ) { Thread.Sleep(100); worker.ReportProgress(i); } } }}
评论