user5226582
user5226582

Reputation: 1986

How to block a window as if Dialog window was displayed

I have a form which I would like to block during execution of an async event. I would like to achieve an effect similar to when a dialog window is displayed, without displaying or creating one.

I don't want to manually disable controls on the form, as some controls may be added in the future (not necessarily by me). I would like to avoid disabling the entire form / user control for aesthetic reasons.

Is there a standard/elegant way of achieving this, or am I going in a wrong direction?

Upvotes: 1

Views: 402

Answers (1)

Andrey Tretyak
Andrey Tretyak

Reputation: 3231

You can block WinForm window by setting it's Enabled property to false, but it will prevent user from any action with that window (like moving, resizing or hiding) and it may be very annoying. Consider showing some load indicator instead.

I would not recommend to disable controls without making them look disabled because it could confuse user.

Edit: As @AvoNappo pointed out window behavior differs depend on where to set Enable property to false:

  • if you set it in the constructor user still will be able to move/minimize/close window;

  • if you call it after constructor window control buttons and windows movement also will be blocked.

Upvotes: 1

Related Questions