如何将 WaitCursor 光标设置在禁用的 WinForms 上

Roy*_*Lee 5 c# winforms

我尝试过以下方法

this.Cursor = Cursors.WaitCursor; //OR 
this.UseWaitCursor = true; //OR 
Application.UseWaitCursor = true; //OR 
Application.DoEvents(); //AND
Run Code Online (Sandbox Code Playgroud)

,但显然当添加以下行时等待光标没有显示:

this.Enabled = false;
Run Code Online (Sandbox Code Playgroud)

P/S:this指窗口形式。


问题:

如何将 WaitCursor 光标设置在禁用的 WinForms 上?

B.K*_*.K. 0

您应该以不同的方式处理事情...不应该有理由禁用表单来阻止用户交互。使用带有进度条或消息的对话框,让用户知道发生了什么。不要给用户留下程序挂起或崩溃的印象。这是一条可怕的路线。从用户的角度思考一下,当您使用其他程序时,是什么让您感到沮丧。

然而,这对我有用:

this.Enabled = false;
this.UseWaitCursor = true;
Run Code Online (Sandbox Code Playgroud)

显然,它仅在光标位于表单上时显示。

这是完整的测试代码:

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;
    }
}
Run Code Online (Sandbox Code Playgroud)