BlackWaspTM

This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Windows Programming
.NET 1.1+

Hiding the Mouse Pointer

Some applications require that the mouse pointer be hidden during use. Examples of such software include screen savers and graphical applications or games. Each may fundamentally change the manner of display or the general behaviour of the cursor.

Hide and Show Methods

If you are developing a screen saver or an application that requires the mouse pointer to behave in a manner that is different to the normal cursor, you may wish to hide the mouse pointer when it falls within the boundaries of your application's forms. In the case of games or graphical software, you may be hiding the pointer so that you can replace it with custom behaviour using GDI drawing facilities or some other means of display.

The cursor can be hidden and redisplayed easily using two static methods of the Cursor class, which is found in the System.Windows.Forms namespace. The Hide method hides the cursor from view when the user moves it over any form within the application. It appears again once the pointer moves outside of those windows. If you wish to make the area where the pointer is hidden smaller than this, call the methods from within the MouseEnter and MouseLeave events of specific controls.

Cursor.Hide();

To redisplay the cursor you may call the static Show method. It should be noted that you need to make the same number of calls to the Show method as you previously did to the Hide method before the pointer reappears. This is useful as you can call the Hide method from several places in your code with each calling Show when it completes. In this situation the mouse pointer will remain hidden until all of the calls to Show have been made. You should ensure that any exceptions thrown between a Show and a Hide do not cause one of the Hide calls to be missed.

Cursor.Show();
28 June 2009