Главная страница | назад





Article #26474: How do I limit the movement of the mouse cursor?

Question:

How do I limit the mouse movement to a certain area?

Answer:

Use the Windows API function ClipCursor(). For example, insert this code into a form's OnMouseDown event handler:

ClipCursor(&BoundsRect);

and this code to the form OnMouseUp event handler:

ClipCursor(NULL);

When you click and hold the mouse on the form, you will not be able to move the mouse outside of the form.

Last Modified: 13-MAR-02