Search code examples
c#winformswindows-forms-designerbusyindicatorbusy-waiting

What is the best way to prevent user click anything on the form while processing on background?


I am working on an Youtube Mp3 converter. Mp3 converting takes a few seconds and I want the user not able to click any control on the form. I have done it using Control.Enabled = false for all control but I think this way is not professional and doesn't seems good for visuality. Is there any good method to do this?


Solution

  • As comments says you can have a modal form:

    yourModalForm.ShowDialog();
    

    Which have no title bar buttons or no title bar at all and will close itself after conversion is done.

    Or you can use Enabled property as yourself suggested but not for every control, you can do it for your whole form at once:

    this.Enabled = false;
    

    Remember that this is your form if you are in the right context.

    I also suggest you to change your form cursor, like that:

    this.Cursor = Cursors.WaitCursor;
    

    And when your work is finished all you have to do is:

    this.Enabled = true;
    this.Cursor = Cursors.Default;