简体   繁体   中英

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.

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. T__T

Start the form using Form.ShowDialog() instead of 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

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

You should show the progress bar as modal dialog, please check whether this answer work for you javasript like model window on winform

HTH.

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.

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