Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

The Cursor.Clip Property

0.00/5 (No votes)
29 Apr 2012 1  
Freezing the Windows Cursor is done in an easy one-liner

Introduction

Sometimes you may want to set the Cursor's bounds, e.g. to forbid the user leaving the form with the cursor.

How To Do

In the Cursor class, there's a property named Clip that enables you to set a Rectangle in which the user can move the cursor.

VB.NET

Forbid to leave form:

Cursor.Clip = Me.Bounds

Make moving possible again:

Cursor.Clip = Rectangle.Empty

C#

Forbid to leave form:

Cursor.Clip = this.Bounds;

Make moving possible again:

Cursor.Clip = Rectangle.Empty;

Points of Interest

This property will be reset if the form loses focus. So If you really want to prohibit the user to move the cursor out of the form, you'll have to set the bounds every time in the Form.MouseEnter event.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here