/// <summary>
/// Call to toggle between the current cursor and the wait cursor
/// </summary>
/// <param name="control">The calling control.</param>
/// <param name="toggleWaitCursorOn">True for wait cursor, false for default.</param>
public static void UseWaitCursor(this Control control, bool toggleWaitCursorOn)
{
...
control.UseWaitCursor = toggleWaitCursorOn;
// Because of a weird quirk in .NET, just setting UseWaitCursor to false does not work
// until the cursor's position changes. The following line of code fakes that and
// effectively forces the cursor to switch back from the wait cursor to default.
if (!toggleWaitCursorOn)
Cursor.Position = Cursor.Position;
}
public sealed class WaitCursor : IDisposable
{
public WaitCursor()
{
Application.UseWaitCursor = true;
Cursor.Current = Cursors.WaitCursor;
}
public void Dispose()
{
Application.UseWaitCursor = false;
Cursor.Current = Cursors.Default;
}
}
字符串 在C#中使用var变得非常简单(示例):
using var waitCursor = new WaitCursor();
using var dbContext = new MyDbContext();
await dbContext.Adresses.LoadAsync();
var adresses = _dbContext.Adressen.Local.ToBindingList();
gridControl1.DataSource = adresses;
6条答案
按热度按时间kognpnkq1#
事实上,还有一种方法可以做到这一点,这是我在研究这个问题几个小时后发现的。
不幸的是,这是一个黑客。
下面是我写的一个方法来处理这个问题。
字符串
ltqd579y2#
还有一种方法:
字符串
完成后,只需将光标变回:
型
atmip9wb3#
我无法复制这种行为?对我来说很好。
但是,如果使用
Control.Cursor = Cursors.WaitCursor
方法,需要注意的一点是,它通常是这样使用的:this.Cursor = Cursors.WaitCursor
个这看起来工作正常,但是,
this
引用表单,所以如果用户将鼠标移动到不同的控件,例如TextBox,那么鼠标不会显示等待光标。这可能会给用户造成混乱,或者当应用程序忙碌忙于其他工作时,如果用户继续处理其他事情,可能会导致一些问题。
ve7v8dk24#
我的解决办法...
字符串
flseospp5#
手动设定光标。我就是这么做的。
dsekswqp6#
一个可重用的解决方案是使用一个小的一次性助手类。
字符串
在C#中使用var变得非常简单(示例):
型
默认光标将在当前代码块的末尾自动恢复。不需要显式的try-finally来确保代码安全。