C#使用进度条,并用线程模拟真实数据 ProgressBar用法(转)
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading; using System.Windows.Forms; namespace jmyd.form { public partial class ProgressBarForm : Form { public ProgressBarForm() { InitializeComponent(); } private void ProgressBarForm_Shown(object sender, EventArgs e) { Thread myThread = new System.Threading.Thread(new ThreadStart(Send)); myThread.IsBackground = true; myThread.Start(); } //模拟进度条 private void Send() { int i = 0; while (i <= 100) { //显示进度信息 this.ShowPro(i); if (i == 100) { i = 0; } i++; //模拟发送多少 Thread.Sleep(500); } Thread.CurrentThread.Abort(); } private delegate void ProgressBarShow(int i); private void ShowPro(int value) { if (this.InvokeRequired) { this.Invoke(new ProgressBarShow(ShowPro), value); } else { this.prcBar.Value = value; this.label1.Text = value + "% Processing..."; } } } }
这个是在线程中更新进度条的,但是C#还有其他的方法更新进度条,有时间进一步研究。