Click here to Skip to main content
11,410,365 members (57,850 online)
Click here to Skip to main content

The Cursor.Clip Property

, 29 Apr 2012 CPOL
Rate this:
Please Sign up or sign in to vote.
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, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Raffael Foidl
Student
Austria Austria
No Biography provided

Comments and Discussions

 
SuggestionPlease explain the motivation for doing this. PinmemberJohn Brett30-Apr-12 0:21 
GeneralRe: Please explain the motivation for doing this. PinmemberRaffael Foidl30-Apr-12 3:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150414.5 | Last Updated 29 Apr 2012
Article Copyright 2012 by Raffael Foidl
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid