f2.show()方法不显示form2中的进度条
我的申请有 2 个表格。第一个是我完成所有工作的地方,第二个只是用于显示进度条。
我想从主窗体打开第二个。如果我使用
Form2 newForm = new Form2();
newForm.Show();
Form2
在需要打开和关闭时打开和关闭,但我看不到进度条。我只能看到一个空白而不是它。
当我使用时,
Form2 newForm = new Form2();
newForm.ShowDialog();
我可以看到进度条,但 Form2
在需要时不会关闭。它永远运行,我该怎么办?
我使用静态公共变量 closeForm 来关闭第二个表单。当我需要关闭我设置的表单
closeForm = true;
和第二个表单时,我有一个计时器,
private void timer1_Tick(object sender, EventArgs e)
{
if (Form1.closeForm)
{
this.Dispose();
this.Close();
return;
}
else
{
progVal++;
progressBar1.Value = (progVal % 100);
}
}
这是我放置 ProgressBar 值并关闭表单的地方。
当我使用 show 方法时,我只看到空白而不是 form2 中的控件。不仅仅是进度条,我希望 form1
关闭 form2
I have an application that has 2 forms. First one is where I do all the job and second one is just for displaying a progressbar.
I want to open the second one from the main form. if I use
Form2 newForm = new Form2();
newForm.Show();
Form2
opens and closes when it needs to open and close, but I cannot see the progress bar. I just can see a blank instead of it.
When I use
Form2 newForm = new Form2();
newForm.ShowDialog();
I can see the progressbar but Form2
doesn't close when it needs. It runs forever, what should I do?
I use a static public variable closeForm to close the second form. When I need to close the form I set
closeForm = true;
and in the second form, I have a timer
private void timer1_Tick(object sender, EventArgs e)
{
if (Form1.closeForm)
{
this.Dispose();
this.Close();
return;
}
else
{
progVal++;
progressBar1.Value = (progVal % 100);
}
}
this is where I put the ProgressBar value and close the form.
When I use show method, I only see blanks instead of the controls in form2. not just the progressbar, and I want form1
to close form2
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,您需要向进度条报告进度,
尝试先这样做,然后调用 this.close();
first of all you need to report progress to progressbar
try doing that first then call this.close();
正如我在评论中所说,您需要从这里检查模态对话框 Form.ShowDialog方法,我只是在那里引用以下表单:
至于为什么您无法使用
Show();
在Form2
上看到ProgressBar
,您需要提供有关如何处理它的更多信息,如下所示如果我将您的程序分成两部分并使用两个按钮单击
来运行它们(单击button1以显示Form2
;然后单击button2以关闭它)我可以看到您的预期结果:进度条
。如果没有您的进一步信息,我最好的猜测是正在运行的某些东西会阻止 Form2 更新其 GUI。
As I said above in the comment, you need to check Modal dialog from here Form.ShowDialog Method, and I just quote the following form there:
As why you can't see your
ProgressBar
onForm2
withShow();
you need to provide more information of how you handles it, as if I separate your program into two parts and use twobutton click
to run them (Click button1 to showForm2
; and click button2 to close it) I can see your expected result: theprogressbar
.Without your further information, my best guess is something running prevents the Form2 to update its GUI.