简体   繁体   English

触发新窗口时关闭进度条

[英]turn off progressbar when new window is fired

I have two forms. 我有两种形式。 MainForm and ProductDetailForm MainFormProductDetailForm

Inside MainForm there is txtSearchBox input box and some radio values to filter search. MainForm内部有txtSearchBox输入框和一些用于过滤搜索的单选值。 When search is performing progressbar is displayed. 搜索执行时,将显示progressbar Initially progress bar is set to Visible = false; 最初,进度条设置为Visible = false;

On btnSearch click event I'm calling background_worker to perform search. 在btnSearch点击事件上,我正在调用background_worker进行搜索。 Immediatly progressbar is set to Visible = true. 立即将progressbar设置为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. 当找到数据并且在MainForm progressBar上打开新窗口( ProductDetailForm )仍然可见时,所以我的问题是在打开新窗口时如何将Visible设置为false。

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: 您可以将打开新表单并将进度条隐藏到RunWorkerCompleted方法中:

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);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM