Make mouse with busy icon (C#) [duplicate]
Asked Answered
C

4

8

I have an application that takes a couple of seconds to run. Is it possible to make the mouse with the busy icon while the app is processing?

Cleres answered 25/3, 2010 at 15:15 Comment(0)
K
18

Use Cursor.WaitCursor property.

You can use:

Cursor.Current = Cursors.WaitCursor;

and as long as there is some processing going on in a WinForms application, the cursor stays in the WaitCursor state.

You can as well use your custom designed cursors:

Cursor.Current = new Cursor("C:\\Cursors\\MyWait.cur");

source: http://bytes.com/topic/c-sharp/answers/238623-how-change-mouse-cursor-busy-state

Kero answered 25/3, 2010 at 15:16 Comment(2)
The UseWaitCursor property is more reliable.Ite
The UseWaitCursor property is not at all more reliable. For tasks that momentarily block the UI thread, the cursor won't change until after the task has completed and returned control to Windows.Armond
I
8

You need to set the form's UseWaitCursor property to true. (And remember to set it to false again afterwords, preferably in a finally block)

You can also set Application.UseWaitCursor to true to apply it to every form.

Ite answered 25/3, 2010 at 15:18 Comment(0)
C
2

I have no option to add my answer as a comment to SLaks answer, so i post it as an answer

In order to force application to set cursor to wait cursor at once, you have to call for Application.DoEvents() method after setting Application.UseWaitCursor, otherwise it might be changed after the lengthy process has been completed

    Application.UseWaitCursor=true;
    Application.DoEvents();
Calfskin answered 12/6, 2013 at 12:58 Comment(0)
C
1
Cursor.Current = Cursors.WaitCursor;

You will need a reference to System.Windows.Forms to change the cursor.

Caligula answered 25/3, 2010 at 15:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.