You see, I thought MouseMove was when the mouse is over this object only. But apparently the MouseMove event will continue to fire even when the mouse moves outside the object so long as the left button was still held down.
The other issue was that the control has to move within its container's coordinate space, but e.X and e.Y of the MouseMove event are referenced to the control's coordinate space. So in the end, I have to use a global variable to track the old mouse coordinates to determine relative motion instead.
And then so as not to exceed the container's boundaries, I had to test for this.parent.ClientSize. This is not exactly perfect as there is no way to find out whether the parent has added things such as scrollbars which would reduce the surface area.
I wonder if there is a better way of moving a draggable control. I don't want to reinvent the wheel. |