Disable & ldquo; Close & rdquo; when another dialog is at the 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?

p.s. 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 (e.g. Cancel, OK, Yes, No, etc.) in case any action needs to be taken as a result.