none
Change cursor to waiting RRS feed

  • Question

  • 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.
    Tuesday, August 5, 2008 3:58 PM

Answers

  • 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: http://msdn.microsoft.com/en-us/library/system.windows.forms.cursors.aspx

    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"?
    • Marked as answer by jack 321 Friday, August 8, 2008 3:09 AM
    Tuesday, August 5, 2008 4:45 PM
  • 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;

    Regards,

    • Edited by Jayanta Dey Tuesday, August 5, 2008 4:08 PM updated
    • Marked as answer by jack 321 Friday, August 8, 2008 3:08 AM
    Tuesday, August 5, 2008 4:07 PM
  •  
    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
    • Marked as answer by jack 321 Friday, August 8, 2008 3:09 AM
    Tuesday, August 5, 2008 4:14 PM
  • 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
    • Marked as answer by jack 321 Friday, August 8, 2008 3:09 AM
    Tuesday, August 5, 2008 4:45 PM
  •  Yeah this will only change the cursor if it hovering over the form that executes the code, if that form has focus. 
    • Marked as answer by jack 321 Friday, August 8, 2008 3:09 AM
    Tuesday, August 5, 2008 7:34 PM
  • Check this thread.
    Hans Passant.
    • Marked as answer by jack 321 Friday, August 8, 2008 3:09 AM
    Wednesday, August 6, 2008 1:30 AM
    Moderator

All replies

  • 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;

    Regards,

    • Edited by Jayanta Dey Tuesday, August 5, 2008 4:08 PM updated
    • Marked as answer by jack 321 Friday, August 8, 2008 3:08 AM
    Tuesday, August 5, 2008 4:07 PM
  •  
    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
    • Marked as answer by jack 321 Friday, August 8, 2008 3:09 AM
    Tuesday, August 5, 2008 4:14 PM
  • I am compiling the application to work with .Net 2.0 so that may be why, although I have 3.5 installed.
    Tuesday, August 5, 2008 4:40 PM
  • I can get access to the Cursor data type but do not know how to access the current cursor and change it.
    Tuesday, August 5, 2008 4:41 PM
  • 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: http://msdn.microsoft.com/en-us/library/system.windows.forms.cursors.aspx

    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"?
    • Marked as answer by jack 321 Friday, August 8, 2008 3:09 AM
    Tuesday, August 5, 2008 4:45 PM
  • 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
    • Marked as answer by jack 321 Friday, August 8, 2008 3:09 AM
    Tuesday, August 5, 2008 4:45 PM
  • 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.
    • Edited by lesnaubr Tuesday, August 5, 2008 4:55 PM spelling
    Tuesday, August 5, 2008 4:49 PM
  • 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. 
    Tuesday, August 5, 2008 5:33 PM
  • 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.
    Tuesday, August 5, 2008 6:42 PM
  • 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"?
    Tuesday, August 5, 2008 7:10 PM
  • 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.
    Tuesday, August 5, 2008 7:23 PM
  •  Yeah this will only change the cursor if it hovering over the form that executes the code, if that form has focus. 
    • Marked as answer by jack 321 Friday, August 8, 2008 3:09 AM
    Tuesday, August 5, 2008 7:34 PM
  • Check this thread.
    Hans Passant.
    • Marked as answer by jack 321 Friday, August 8, 2008 3:09 AM
    Wednesday, August 6, 2008 1:30 AM
    Moderator
  • Cursor.Current=Cursors.WaitCursor; for waiting cursor 

    cursor.current=Cursors.Default;

    Sunday, July 15, 2012 8:36 AM
  • Thanks! Just what I needed.

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

    Thursday, August 22, 2019 9:17 PM