How to Change the Cursor to a Wait Cursor in C#
By FoxLearn 12/12/2024 9:58:34 AM 80
How to Display the Wait/Busy Cursor in C#?
In a Windows Forms application, you can change the cursor to a wait cursor using Cursor.Current
or the UseWaitCursor
property of a form or control.
For example, Using Cursor.Current
// Change the cursor to the wait cursor Cursor.Current = Cursors.WaitCursor; // Do something // Change the cursor back to the default arrow Cursor.Current = Cursors.Default;
The Cursor.Current
property is used to globally change the cursor for the entire application or when you want to specifically change the cursor in certain parts of the application.
For example, Using UseWaitCursor
// Set the form's UseWaitCursor property to true this.UseWaitCursor = true; // Do something // Set the form's UseWaitCursor property to false to restore the default cursor this.UseWaitCursor = false;
The UseWaitCursor
property is often used in Windows Forms because it automatically sets the cursor to the wait cursor when set to true
for the form.
In a WPF application, you can set the cursor using the Mouse.OverrideCursor
property.
// Change the cursor to the wait cursor Mouse.OverrideCursor = Cursors.Wait; // Do something // Change the cursor back to the default arrow Mouse.OverrideCursor = null; // Reset to the default cursor
The Mouse.OverrideCursor
property allows you to set a custom cursor for the entire application. Setting it to Cursors.Wait
will make the cursor appear as the 'wait' cursor.
By using the above methods, you can easily set the wait cursor while performing long-running tasks in your C# applications and improve the user experience by indicating that the application is busy.
- How to use BlockingCollection in C#
- Calculating the Distance Between Two Coordinates in C#
- Could Not Find an Implementation of the Query Pattern
- Fixing Invalid Parameter Type in Attribute Constructor
- Objects added to a BindingSource’s list must all be of the same type
- How to use dictionary with tuples in C#
- How to convert a dictionary to a list in C#
- Dictionary with multiple values per key in C#