I have two forms. MainForm
and ProductDetailForm
Inside MainForm
there is txtSearchBox
input box and some radio values to filter search. When search is performing progressbar
is displayed. Initially progress bar is set to Visible = false;
On btnSearch click event I'm calling background_worker to perform search. Immediatly progressbar is set to Visible = true.
When data is found and new window ( ProductDetailForm
) is opened on the MainForm progressBar is still visible, so my question is how to set Visible to false when new window is opened.
private void bntSearch_Click(object sender, EventArgs e)
{
progressBarControll.Visible = true;
backgroundWorker1.RunWorkerAsync();
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
MyData data = repository.GetData(1);
// tried here progressBarControll.Visible = false;
// but it raises an exception
var detailsForm = new ProductDetailForm(data);
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
progressBarControll.Visible = false;
}
You can move both opening the new form and hiding the progress bar to RunWorkerCompleted
method:
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
MyData data = repository.GetData(1);
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
progressBarControll.Visible = false;
var detailsForm = new ProductDetailForm(data);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.