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.