Current .Net Version: 2.0.50727
Home
Articles
C# & .Net Framework Reference
Practice C# Online
XML Web Services
RSS Feeds
Code Snippets
T-SQL Scripts
Videos
Valuable Links
Contact Us
Mike's C#, VS.NET and SQL Blog




ROR XML Info.
What's New in Windows Forms 2.0 - Turning On and Off Hourglass Cursors with UseWaitCursor
Author: Michael G.     Last Updated:12/14/2005 4:13:07 PM
Category(ies): Windows Forms 2.0, Visual C# 2.0, .Net Framework 2.0
Description: Learn about the new Windows Forms' UseWaitCursor property in .Net Framework 2.0.
  Add & View Comments About this Article

Tested with MS Visual Studio 2005 8.0.50727.42; .NET 2.0.50727

A new property has been added to the Control (in System.Windows.Form) class: UseWaitCursor. This property simply sets the control's Cursor property. When UseWaitCursor is set to true, the control's Cursor property is set to Cursors.WaitCursor. When UseWaitCursor is set to false, the control's Cursor property is set to Cursors.Default.

The Application class also contains a UseWaitCursor property. This property sets the UseWaitCursor property of any open Forms in the application.

Please note that you must set UseWaitCursor to false in order to change the control's Cursor property back to Cursors.Default; otherwise, you'll constantly see an hourglass mouse cursor for the affected control(s).

Implementing UseWaitCursor is similar to setting the control's Cursor property: /******* UseWaitCursor Method *******/ // Display an hourglass cursor: this.UseWaitCursor = true; // Do something that takes a long time here ... // We're all done so we can change cursor back: this.UseWaitCursor = false; /******* Cursor Method *******/ // Display an hourglass cursor: this.Cursor = Cursors.WaitCursor; // Do something that takes a long time here ... // We're all done so we can change cursor back: this.Cursor = Cursors.Default; Displaying an hourglass (WaitCursor) cursor for all opened Forms in an application during a long-running operation: // Display an hourglass for all forms in the application: Application.UseWaitCursor = true; // Do something that takes a long time here and impacts all forms ... // We're all done so we can change cursor back: Application.UseWaitCursor = false; Displaying an hourglass (WaitCursor) cursor for a Form during a long-running operation: // Display an hourglass cursor for a Form: this.UseWaitCursor = true; // Do something that takes a long time here ... // We're all done so we can change cursor back: this.UseWaitCursor = false;

MSDN2 Reference Information for UseWaitCursor.



Comments Click Here to Add your Comment
No Comments Found.
 
COPYRIGHT/DISCLAIMER | CONTACT US