我怎样才能使光标转到等待光标? [英] How can I make the cursor turn to the wait cursor?
问题描述
我有一个C#应用程序,有用户登录到它,因为哈希算法是昂贵的,它需要一点时间做。我怎样才能显示等待/忙状态光标(通常是沙漏)给用户,让他们知道程序正在做什么?
I have a C# application that has users login to it, and because the hashing algorithm is expensive, it takes a little while to do. How can I display the Wait/Busy Cursor (usually the hourglass) to the user to let them know the program is doing something?
该项目是在C#。
推荐答案
您可以使用<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.cursor.current.aspx"><$c$c>Cursor.Current$c$c>.
// Set cursor as hourglass
Cursor.Current = Cursors.WaitCursor;
// Execute your time-intensive hashing code here...
// Set cursor as default arrow
Cursor.Current = Cursors.Default;
但是,如果散列操作的真正的漫长(MSDN这个定义为超过2-7秒),你应该使用其他视觉反馈指示器比光标以通知用户进展。为了更深入的一套指南,请参见这篇文章。
However, if the hashing operation is really lengthy (MSDN defines this as more than 2-7 seconds), you should probably use a visual feedback indicator other than the cursor to notify the user of the progress. For a more in-depth set of guidelines, see this article.
编辑:
正如@Am指出的那样,你可能需要调用 Application.DoEvents();
在 Cursor.Current = Cursors.WaitCursor;
,以确保实际显示沙漏。
As @Am pointed out, you may need to call Application.DoEvents();
after Cursor.Current = Cursors.WaitCursor;
to ensure that the hourglass is actually displayed.
这篇关于我怎样才能使光标转到等待光标?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!