Saturday, October 4, 2008

Hourglass Cursor in C#

This example demonstrates how to show hourglass in C#.

Hourglass cursor

Mouse cursor displayed over any control in windows forms application is determined by Control.Cursor property. If you want to change the mouse cursor at application level use static property Current of Cursor class. To show hourglass cursor assign value Cursors.WaitCur­sor. To return back the default behavior (to display control specific cursor) assign back value Cursors.Default to the Cursor.Current property. See example below.

// hourglass cursor
Cursor.Current = Cursors.WaitCursor;
try
{
Thread.Sleep(5000); // wait for a while
}
finally
{
Cursor.Current = Cursors.Default;
}

resource from http://www.csharp-examples.net/

0 comments: