Click here to Skip to main content
12,452,056 members (59,238 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as

Stats

10.4K views
Posted

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

You may also be interested in...

Pro
Pro

Comments and Discussions

 
SuggestionPlease explain the motivation for doing this. Pin
John Brett29-Apr-12 23:21
memberJohn Brett29-Apr-12 23:21 
GeneralRe: Please explain the motivation for doing this. Pin
Raffael Foidl30-Apr-12 2:38
memberRaffael Foidl30-Apr-12 2:38 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    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
Web02 | 2.8.160826.1 | Last Updated 29 Apr 2012
Article Copyright 2012 by Raffael Foidl
Everything else Copyright © CodeProject, 1999-2016
Layout: fixed | fluid