Change cursor to waiting RRS feed

  • 質問

  • I have found samples online using the System.Windows.Input namespace to change the cursor to a different state but this namespace does not exist on my machine. I'm not sure if it have been removed from .Net or what. I'm pretty sure that the code should set something equal to Cursors.WaitCursor as in:

    Cursor = Cursors.WaitCursor;

    I need a way to change the cursor to the busy state and then back to a normal state. I just do not know what to fill in for Cursor. Any help would be greatly appreciated. Thanks.
    2008年8月5日 15:58



  • Hi,

    System.Windows.Input is part of WPF (.NET 3.0/3.5).

    Which framework /VS version you are working with?

    if you are working with .NET 2.0 and VS 2005, you can still write:

    Cursor = Cursors.WaitCursor;


    • 編集済み Jayanta Dey 2008年8月5日 16:08 updated
    • 回答としてマーク jack 321 2008年8月8日 3:08
    2008年8月5日 16:07
    If you are using older versions of .NET (not 3.0/3.5) the cursor is in  System.Windows.Forms

    You might just be missing a reference
    • 回答としてマーク jack 321 2008年8月8日 3:09
    2008年8月5日 16:14
  • I am compiling the application to work with .Net 2.0 so that may be why, although I have 3.5 installed.
    2008年8月5日 16:40
  • I can get access to the Cursor data type but do not know how to access the current cursor and change it.
    2008年8月5日 16:41
  • For clarification the Windows.Forms version is still there for .NET 3.0/3.5, not just 2.0, but WPF has its own namespace.

    lesnaubr, have a look here for more detail:

    All you need to do is:

    // Waiting / hour glass 
    Cursor.Current = Cursors.WaitCursor; 
    // Back to normal 
    Cursor.Current = Cursors.Default; 

    And IntelliSense should pick up the different variations for your use.

    Document my code? Why do you think it's called "code"?
    • 回答としてマーク jack 321 2008年8月8日 3:09
    2008年8月5日 16:45
  • If you are want to set the cursor from some method within your form class, you can directly say:

    Cursor = Cursors.WaitCursor; // it will point to the current cursor
    • 回答としてマーク jack 321 2008年8月8日 3:09
    2008年8月5日 16:45
  • Thank you very much everyone. I actually just discovered Cursor.Current right after I posted my third message in this thread but for some reason, it does not actually change the cursor. I can see it flicker to the busy cursor but then it just goes back to normal right away. I'm thinking something else is changing it back to normal by default. Will the cursor change only be in effect within the running application? I do not actually show any windows or forms when this application is running. I just want the cursor to be in a busy state.
    • 編集済み lesnaubr 2008年8月5日 16:55 spelling
    2008年8月5日 16:49
  • The code provided by the others will work only if you've got a form visible.  Are you sure you really want the cursor to be changed by a program that is running [apparently] in the background?  If I've got your app running on my machine but I'm busy working in Outlook, the cursor should represent what I'm doing in Outlook. 
    2008年8月5日 17:33
  • It will make sense within the context of the program. The program has a main UI which will be running at all times and when a certain button is clicked and an action is performed, the cursor should be busy until it is finished. There should not be any confusion on the user's end.
    2008年8月5日 18:42
  • Well, if you can't get the Cursor to work from any of the previous posts, and since you're only trying to get the WaitCursor working and not other types of cursors, another possibility is using the Application.UseWaitCursor property.

    Application.UseWaitCursor = true;  // on 
    Application.UseWaitCursor = false// off 

    Document my code? Why do you think it's called "code"?
    2008年8月5日 19:10
  • Hmmm.... that didn't work either. I'm beginning to think that I cannot do what I want with the nature of the program I am coding. The process that I am running in the background is in a separate thread from the main UI so I think that is why the wait cursor is not showing up.
    2008年8月5日 19:23
  •  Yeah this will only change the cursor if it hovering over the form that executes the code, if that form has focus. 
    • 回答としてマーク jack 321 2008年8月8日 3:09
    2008年8月5日 19:34
  • Check this thread.
    Hans Passant.
    • 回答としてマーク jack 321 2008年8月8日 3:09
    2008年8月6日 1:30
  • Cursor.Current=Cursors.WaitCursor; for waiting cursor 


    2012年7月15日 8:36
  • Thanks! Just what I needed.

    "Document my code? Why do you think it's called "code"?"  Love it!

    2019年8月22日 21:17