5

I have tried the following

this.Cursor = Cursors.WaitCursor; //OR 
this.UseWaitCursor = true; //OR 
Application.UseWaitCursor = true; //OR 
Application.DoEvents(); //AND

, but apparently the wait cursor didn't show up when the following line is added:

this.Enabled = false;

P/S: this refers to window form.


Question:

How can I set WaitCursor cursor over disabled WinForms?

Roy Lee
  • 10,572
  • 13
  • 60
  • 84
  • Is there a good reason why would you want to disable a form? I don't think it's a good practice as it will stop receiving messages so the events handlers won't fire up! I would consider redesign. For e.g: disable all controls (simple foreach loop). – etaiso Feb 20 '14 at 07:38
  • possible duplicate of [Cursor.Current vs. this.Cursor](http://stackoverflow.com/questions/302663/cursor-current-vs-this-cursor) – Hans Passant Feb 20 '14 at 10:24

1 Answers1

0

You should handle things differently... there shouldn't be a reason to disable the form to prevent user interaction. Use a dialog box with a progress bar or a message that lets the user know what is going on. Don't give user an impression that the program is hanging or crashing. That is a horrible route to take. Think of a user perspective and what frustrated you when you use others' programs.

However, this worked for me:

this.Enabled = false;
this.UseWaitCursor = true;

Obviously, it only displays when cursor is over the form.

Here's the entire test code:

namespace WindowsFormsApplication1
{
    partial class Form1
    {
        private System.ComponentModel.IContainer components = null;

        protected override void Dispose(bool disposing)
        {
            if (disposing && (components != null))
            {
                components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.button1 = new System.Windows.Forms.Button();
            this.SuspendLayout();

            this.button1.Location = new System.Drawing.Point(163, 110);
            this.button1.Name = "button1";
            this.button1.Size = new System.Drawing.Size(75, 23);
            this.button1.TabIndex = 0;
            this.button1.Text = "button1";
            this.button1.UseVisualStyleBackColor = true;

            this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
            this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
            this.ClientSize = new System.Drawing.Size(284, 262);
            this.Controls.Add(this.button1);
            this.Name = "Form1";
            this.Text = "Form1";
            this.ResumeLayout(false);
            this.Enabled = false;
            this.UseWaitCursor = true;
        }

        private System.Windows.Forms.Button button1;
    }
}
B.K.
  • 9,982
  • 10
  • 73
  • 105