c# - 从默认光标切换到等待 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;
}
解决方案
正如@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;
}
}
推荐阅读
- javascript - 从 Javascript 中选择的选项卡中捕获文本
- javascript - 将“新日期”更改为输入值
- mysql - MySQL - 使用 DATETIME 日期和间隔计算每日 7 天移动总和
- postgresql - 在 postgres 中估计一个 SQL 请求的结果大小
- python - 操纵数据框以创建数据透视表
- qt - QSplitter 似乎反转索引内容小部件
- amazon-web-services - 我如何从前端获取输入字符串?
- git - 使用启动脚本从 Gitlab 存储库部署服务时出现问题
- android - 用于 EditText 的具有数字和基本数学运算的键盘
- c# - StackExchange.Redis 使用哈希真的很慢 = C# ASP.NET Core 3.0 和 Docker