加载表单时 C# WaitCursor

标签 c# winforms forms cursors

我有一个需要几秒钟才能最终显示的表单。此表单通过以下方式调用:

using (ResultsForm frm = new ResultsForm())
{
    this.Visible = false;
    frm.ShowDialog();
    this.Visible = true;
}

在等待表单最终显示时,将默认光标设置为 Cursors.WaitCursor 很有用。目前,我似乎只能通过使用静态“当前”属性才能成功完成此操作:

using (ResultsForm frm = new ResultsForm())
{
    //this.Visible = false;
    Cursor.Current = Cursors.WaitCursor;
    frm.ShowDialog();
    //this.Visible = true;
}

但这有两个问题:

  • 它迫使我禁用我想保留的 MainForm 隐藏功能。
  • 它增加了耦合,因为 Cursor.Current = Cursor.Default; 需要在 ResultsForm Shown 事件中调用。

如何在加载表单时更改光标而不更改第一个代码片段并避免耦合?

更新: 现在问题已得到解答,视频演示已删除,因此我不会超出 ISP 带宽限制。

最佳答案

It forces me to disable the MainForm hiding feature which I would like to retain.

您应该能够毫无问题地执行这两项操作。

It increases coupling since Cursor.Current = Cursor.Default; needs to be called within the ResultsForm Shown event

您是否尝试过将光标逻辑完全放入 ResultsForm 对话框代码中?您应该能够在 ResultsForm 的构造函数中设置 Cursor.Current = Cursors.WaitCursor;,然后设置 Cursor.Current = Cursor.Default;Shown 事件中设置。

这将使逻辑完全保留在对话框中,而不是在主窗口中。然后,您还可以在主窗口中保持可见性切换。

关于加载表单时 C# WaitCursor,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1822620/

相关文章:

php - 从循环创建的表单中检索多行...卡住了

c# - 如何: Adding Multi tables on Word with .网

c# - 获取configurationRefresher为null

c# - MongoDB C# 驱动程序 2.0 : How to get the result from MapReduceAsync

c# - 如何从通过 USB 连接的相机读取文件

c# - C# WinForms 中的矢量图形——我应该与 WPF 互操作吗?

c# - IronPython 覆盖 __setattr__ 和 __getattr__

c# - 如何将图像设置为缩放至其表格单元格的 100%? (C#/WinForms)

ruby-on-rails - 如何在选择输入中进行收集取决于另一个选择输入的值

php - 如果在 mysql 中有一个数字,则显示文本