在将数据从一个表传输到另一个表时,我想要一个进度条在我的表单上显示状态。我尝试了一些方法,但它不起作用。
if (dataGridView1.RowCount - 1 == no_Of_rows)
{
progressBar1.Value = 100;
dataGridView1.Visible = true;
}
else
{
progressBar1.Value = 50;
dataGridView1.Visible = false;
}
在将数据从一个表传输到另一个表时,我想要一个进度条在我的表单上显示状态。我尝试了一些方法,但它不起作用。
if (dataGridView1.RowCount - 1 == no_Of_rows)
{
progressBar1.Value = 100;
dataGridView1.Visible = true;
}
else
{
progressBar1.Value = 50;
dataGridView1.Visible = false;
}
这是一个如何使用后台工作程序的示例。
private BackgroundWorker worker;
public Form1()
{
InitializeComponent();
this.worker = new BackgroundWorker
{
WorkerReportsProgress = true
};
worker.DoWork += WorkerOnDoWork;
worker.ProgressChanged += WorkerOnProgressChanged;
worker.RunWorkerCompleted += delegate
{
//Set the value of the progressbar to the maximum value if the work is done
this.progressBar1.Value = this.progressBar1.Maximum;
};
worker.RunWorkerAsync();
}
private void WorkerOnProgressChanged(object sender, ProgressChangedEventArgs e)
{
//Set the value of the progressbar, or increment it.
//You can use the e.ProgressPercentage to get the value you set in the DoWork-Method
//The e.UserState ist a custom-value you can pass from the DoWork-Method to this Method
this.progressBar1.Increment(1);
}
private void WorkerOnDoWork(object sender, DoWorkEventArgs e)
{
// Do you stuff here. Here you can tell the backgroundworker to report the progress like.
this.worker.ReportProgress(5);
//You can not access properties from here, so if you want to pass a value or something else to the
//progresschanged-method you have to use e.Argument.
}
这是一个winforms应用程序。在表单上只有一个名为 progressbar1 的进度条
使用进度条窗口控件
供参考: http: //www.codeproject.com/Articles/449594/Progress-Bars-Threads-Windows-Forms-and-You