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

时间:2014-02-20 04:58:14

标签: c# winforms

我试过以下

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

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

this.Enabled = false;

P / S:this指的是窗口形式。


问题:

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

1 个答案:

答案 0 :(得分:0)

您应该以不同的方式处理事情......应该没有理由禁用表单以防止用户交互。使用带有进度条的对话框或允许用户知道发生了什么的消息。不要给用户一个程序挂起或崩溃的印象。这是一条可怕的路线。想一想用户的观点,以及当你使用他人的程序时会让你感到沮丧。

然而,这对我有用:

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

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

以下是整个测试代码:

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;
    }
}