Magnetic Cursor

  • Thread starter Thread starter Charlie Brown
  • Start date Start date
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?
 
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
 
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:
 
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
 
Back
Top