简体   繁体   English

当另一个对话框位于顶部时,禁用“关闭”按钮

[英]disable “Close” button when another dialog is on top

I currently have a problem with forms here. 我目前在表格中遇到问题。

Whenever some process is ongoing, I have a progress dialog that should popup, but when I click the "X" button of the window/form behind my progress dialog, it will be dismissed and the ongoing operation is cancelled. 每当某个进程正在进行时,我都会弹出一个进度对话框,但当我单击进度对话框后面的窗口/表单的“X”按钮时,它将被解除并且正在进行的操作被取消。

How can I prevent that from happening? 我怎样才能防止这种情况发生? Should I have to disable my whole form behind my progress bar? 我是否必须在进度条后面禁用整个表单? and how can I do it? 我该怎么办?

ps I have tried this and this and this but NONE of them seems to work in my application. PS我已经尝试了这个这个这个 ,但他们没有一个似乎在我的应用程序工作。 T__T T__T

Start the form using Form.ShowDialog() instead of Form.Show() . 使用Form.ShowDialog()而不是Form.Show()启动窗体。 That will disable the background form (actually any other form in the process) until the form you are showing closes. 这将禁用背景表单(实际上是进程中的任何其他表单),直到您显示的表单关闭。 As an added benefit you can have the form return a value (eg Cancel, OK, Yes, No, etc.) in case any action needs to be taken as a result. 作为额外的好处,您可以让表单返回一个值(例如取消,确定,是,否等),以防需要采取任何行动。

Not actually the answer you might be expecting, but you could handle the Form.FormClosing event, setting e.Cancel = True 实际上并不是您可能期望的答案,但您可以处理Form.FormClosing事件,设置e.Cancel = True

This won't disable the Close button, but will make your form remain open in this case. 这不会禁用“关闭”按钮,但在这种情况下会使您的表单保持打开状态。

See more at: http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing.aspx 有关详细信息,请访问: http//msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing.aspx

You should show the progress bar as modal dialog, please check whether this answer work for you javasript like model window on winform 你应该将进度条显示为模态对话框,请检查这个答案是否适合你javasript像winform上的模型窗口

HTH. HTH。

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

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