devxlogo

Mouse clipping with the Cursor class

Mouse clipping with the Cursor class

The Clip property of the System.Windows.Forms.Cursor class represents the rectangle within which the mouse cursor is confined, or Nothing if the mouse can move over the entire screen. This rectangle is in screen coordinates, so you must do some conversions if you want to confine the mouse to an object on the form, or the form itself. This task is made easy by the ClientRectangle property and the RectangleToScreen method that all visible controls expose:

' Clip the mouse to the TextBox1 control's client area.Cursor.Clip = TextBox1.RectangleToScreen(TextBox1.ClientRectangle)' ...' Free the mouse cursor.Cursor.Clip = Nothing

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist