首页 > 解决方案 > 从默认光标切换到等待 Winforms

问题描述

当用户点击提交时,我试图将光标从默认更改为等待光标。我试过这个,但它不起作用。我正在从 To 复制文件,因此在完成进度之前,光标必须是等待光标。谢谢

     // Starts the process of copying in background worker

     backgroundCopy.RunWorkerAsync(arguments);
     this.Cursor = Cursors.WaitCursor;

     private void backgroundCopy_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
            {

                //Enable Submit Button
                Submit.Enabled = true;

                // Set Progress Bar to Green
                progressBar1.SetState(1);

                this.lblInfo.Text = "Copy Completed!";

                this.Cursor = Cursors.Default;
            }

标签: c#winforms

解决方案


正如@HansPassant所说,您只需要替换光标分配即可设置您要使用的光标

像这样的东西会适合

private void backgroundCopy_RunWorkerCompleted(object sender, System.ComponentModel.RunWorkerCompletedEventArgs e)
{
    try
    {
        Cursor.Current = Cursors.WaitCursor;
        //DO WORK
        // Set Progress Bar to Green
        progressBar1.SetState(1);
        //...
    }
    finally
    {
        Cursor.Current = Cursors.Default;
    }
}

推荐阅读