1

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

CMA
  • 2,758
  • 5
  • 28
  • 40
  • When showing the progress bar, you should prevent user from clicking any thing in the behind form. – Thinhbk Jun 28 '12 at 03:32
  • 1
    yes. that's it. that's exactly what I wanted to happen..and how can do that? – CMA Jun 28 '12 at 03:46

3 Answers3

3

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.

D Stanley
  • 149,601
  • 11
  • 178
  • 240
1

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

J.Hudler
  • 1,238
  • 9
  • 26
  • This is an interesting approach. Comonly used in multi-threaded applications (i.e. download managers). – J.Hudler Jun 28 '12 at 03:51
0

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

HTH.

Community
  • 1
  • 1
Thinhbk
  • 2,194
  • 1
  • 23
  • 34