How can I display the Wait/Busy Cursor (usually the hourglass) to the user to let them know the program is doing something?
We can set the cursor to wait using object. style. cursor = “wait” in javascript.
To force display of the wait cursor over a given control, call that control's UseWaitCursor method. To make the wait cursor display for the entire application, regardless of the control or form selected, call UseWaitCursor on the Application class.
Gets or sets a value indicating whether to use the wait cursor for the current control and all child controls.
You can use Cursor.Current
.
// Set cursor as hourglass Cursor.Current = Cursors.WaitCursor; // Execute your time-intensive hashing code here... // Set cursor as default arrow Cursor.Current = Cursors.Default;
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.
Edit:
As @Am pointed out, you may need to call Application.DoEvents();
after Cursor.Current = Cursors.WaitCursor;
to ensure that the hourglass is actually displayed.
Actually,
Cursor.Current = Cursors.WaitCursor;
temporarily sets the Wait cursor, but doesn’t ensure that the Wait cursor shows until the end of your operation. Other programs or controls within your program can easily reset the cursor back to the default arrow as in fact happens when you move mouse while operation is still running.
A much better way to show the Wait cursor is to set the UseWaitCursor property in a form to true:
form.UseWaitCursor = true;
This will display wait cursor for all controls on the form until you set this property to false. If you want wait cursor to be shown on Application level you should use:
Application.UseWaitCursor = true;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With