Magnetic Cursor

C

Charlie Brown

I have written some custom controls that can dragged around a container
control. When the controls reach the edges of the container control,
they stop moving. The mouse continues to travel beyond the border of
the control. When the mouse direction of travel changes, the control
then moves accordingly (I tie the movement of the control to the
MousePosition delta). Is there some way to magnet the cursor to the
control, so when the control stops moving the mouse does the same?
 
T

tommaso.gastaldi

Charlie Brown ha scritto:
I have written some custom controls that can dragged around a container
control. When the controls reach the edges of the container control,
they stop moving. The mouse continues to travel beyond the border of
the control. When the mouse direction of travel changes, the control
then moves accordingly (I tie the movement of the control to the
MousePosition delta). Is there some way to magnet the cursor to the
control, so when the control stops moving the mouse does the same?

The most obvious way seems to keep track of the mouse position
under MouseMove and, when you need to freeze it, just:

Windows.Forms.Cursor.Position = PreviousPosition
 
T

tommaso.gastaldi

It depends on how you have implemented it.
I used this technique and to me it worked fine.

If you wish, post a very simplified and working sample of your
code showing the problem, I will be happy to take a look at it...

-T

Charlie Brown ha scritto:
 
S

Scott M.

Left correlates to an x coordinate that is decreasing and Right correlates
to an x coordinate that is increasing. In your event handler check the x
position against the last x position to determine if it's going up or down
and respond accordingly.

-Scott
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top