我有下面的代码,它在加载时只显示一个消息文本框:
private void button3_Click_1(object sender, EventArgs e)
{
int i;
BackgroundWorker bw = new BackgroundWorker();
bw.WorkerReportsProgress = true;
bw.WorkerSupportsCancellation = true;
bw.DoWork += new DoWorkEventHandler(bw_DoWork);
bw.ProgressChanged += new ProgressChangedEventHandler(bw_ProgressChanged);
bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(bw_RunWorkerCompleted);
msgForm = new Form2(); //Form2 is showing a message "Please Wait..."
try
{
bw.RunWorkerAsync(comboBox15.Text);
msgForm.StartPosition = FormStartPosition.CenterParent;
msgForm.ShowDialog();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
void bw_DoWork(object sender, DoWorkEventArgs e)
{
string PrtAdd = e.Argument.ToString();
Loading(PrtAdd); //This is the function of my loading.
}
void bw_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
msgForm.Close();
}
我的加载有时需要 2-3 分钟。所以,如果只是显示一个静态消息框,用户可能会认为我的程序可能挂在某个地方。
我想通过在加载时添加进度条来改进这一点。你们能帮帮我吗?