Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make the cursor turn to the wait cursor?

How can I display the Wait/Busy Cursor (usually the hourglass) to the user to let them know the program is doing something?

like image 329
Malfist Avatar asked Oct 14 '09 19:10

Malfist


People also ask

How do I change my cursor to wait?

We can set the cursor to wait using object. style. cursor = “wait” in javascript.

How to show a wait cursor in c#?

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.

What is UseWaitCursor?

Gets or sets a value indicating whether to use the wait cursor for the current control and all child controls.


2 Answers

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.

like image 88
Donut Avatar answered Sep 26 '22 00:09

Donut


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; 
like image 22
draganstankovic Avatar answered Sep 24 '22 00:09

draganstankovic